the trick with the three letter shorthands are that you cant guarantee their meaning.
Jans_Spreadsheet_March. What month is that file?
Now, if they will always put the date first, this makes it a bit easier.
(completely untested and probably simplifyable)
PHP Code:
$months = array("Jan","Feb"....."January","February"....."December");
$str = str_replace("_"," ",$str); //Make all files space-delimited.
$str = explode(" ",$str);
if(intval($str[0]) == 0 && $str[0] != "00") {
//A Month Came First.
$m_ind = 0;
$y_ind = 1;
} else {
$y_ind = 0;
$m_ind = 1;
}
$file_month = (array_search($str[$m_ind],$months) !== FALSE) ? (array_search($str[$m_ind],$months) % 12) + 1 : FALSE;
$file_year = (strlen($str[$y_ind]) == 4) ? $str[$y_ind] : (($str[$y_ind] < 20) ? "20".$str[$y_ind] : "19".$str[$y_ind]);
$file_month will be an integer in the range 1-12 or FALSE if something other than a month string was detected.
$file_month will be a year in 4-digit format, with a range for 2-to-4 digit conversion of 1921-2020.
Bookmarks