This is a discussion on Re: Q on Regular Expressions - solved within the PHP General forums, part of the PHP Programming Forums category; Once again, I ask a stupid question, wotk on it some more and find the answer under my nose. Thanks ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Once again, I ask a stupid question, wotk on it some more and find the
answer under my nose. Thanks anyway, I have what I'm looking for. Walter BTW: If you would like to know what I did, or even look at it and comment... =================== /* American Standard Format - accepts SLASH or DASH "02/03/1994 14:15:29 EST" -- American Standard 24 Hr Clock "02/03/1994 02:15:29 PM EST" -- American Standard 12 Hr Clock "02/03/1994 14:15:29" -- zone is optional "02/03/1994" -- only date Will work on dates before 1000, but must have leading ZEROs */ $strDate = "01-02-1994"; file://$strDate = "01/02/1994 01:02:03"; file://$strDate = "01/02/1994 01:02:03 GMT"; file://$strDate = "01/02/1994 01:02:03 AM GMT"; $regExp = "^"; // Start at begining of string $regExp .= "("; // Start Date Block $regExp = "([0-9]{2})[-|\/]"; // Month DASH or SLASH $regExp .= "([0-9]{2})[-|\/]"; // Day DASH or SLASH $regExp .= "([0-9]{4})"; // Year $regExp .= ")?"; // End Time Block $regExp .= "("; // Start Time Block $regExp .= "[[:space:]]"; // Space $regExp .= "([0-9]{2}):"; // Hour COLON $regExp .= "([0-9]{2}):"; // Minute COLON $regExp .= "([0-9]{2})"; // Seconds $regExp .= "("; // Start Meridium Block $regExp .= "[[:space:]]"; // Space $regExp .= "[a-zA-Z]{1,2}"; // AM/PM $regExp .= ")?"; // End Meridium Block $regExp .= "("; // Start TZ Block $regExp .= "[[:space:]]"; // Space $regExp .= "[a-z|A-Z]{1,3}"; // Time Zone $regExp .= ")?"; // End TZ Block $regExp .= ")?"; // End Time Block $regExp .= "$"; // End at end of string if (ereg ($regExp, $strDate, $regs)) { echo '<pre>'; echo '|' . $strDate . '|' . '<br />'; echo print_r($regs); echo '</pre>'; } else { echo "Invalid date format: $strDate"; } |