I have a bunch of files for our website that have the months in the file name. However, the months are in sometimes full name, sometimes 3 letter abbreviation.
Now, what I want to do is to rename the file name (I can do that) to a consistant naming convention. I can get the year out of the string ($year = preg_replace("/[^0-9]/", '', $mfiles); where $mfiles is the file name), but cannot figure out the best way to get the 3 letter month from the file name.
I tried the following but get the year only.
Any help is appreciated.Code:$patterns[0] = "/Jan/"; $patterns[1] = "/Feb/"; $patterns[2] = "/Mar/"; $patterns[3] = "/Apr/"; $patterns[4] = "/May/"; $patterns[5] = "/Jun/"; $patterns[6] = "/Jul/"; $patterns[7] = "/Aug/"; $patterns[8] = "/Sep/"; $patterns[9] = "/Oct/"; $patterns[10] = "/Nov/"; $patterns[11] = "/Dec/"; $mfiles = "July_2012_Letter_Document.doc" $year = preg_replace("/[^0-9]/", '', $mfiles); // ditch anything that is not a number $month = preg_replace($patterns, '', $mfiles); echo 'year: ' .$year . ' - month - ' . $month . ' - filename: ' . $mfiles . '<br>';
E



Reply With Quote
Bookmarks