Page 1 of 1

Parsing a file name

Posted: Sun Jan 18, 2009 5:14 pm
by emsenn
I'm working on a script that will be used by a small digital library to rename their files based on a classification schedule. One thing that could greatly speed up the transition is if the script could recommend the basic call numbers for a topic, based on a file's name. Perhaps an example would be helpful:

A file's name is C++, a Beginners Guide.txt. I want to read the string "C++" from that, and based on that recommend a number (004.1.1064). A simple array would work, however there will be some numbers that have more than one keyword tied to them. For example, Metaphysics and Metaphysical both have the same call number.

I'm interested in how to approach a function that would take the file name and find the number based on that - I however have very little clue on what to do beyond that, and any help would be greatly appreciated.

Re: Parsing a file name

Posted: Sun Jan 18, 2009 6:21 pm
by Burrito
if it's going to use any kind of standardization in the filename construction, you could use substr() otherwise you'll want to write a regular expression to extract the info you need from the names with preg_match()