Re: Q on Regular Expressions - solved

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-17-2003
Jswalter
 
Posts: n/a
Default Re: Q on Regular Expressions - solved

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";
}
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:19 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0