Re: preg_match and dates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Michael A. Peters wrote:
This is what I have so far -

$pattern[] = "/^([0-9]{1,2})[\s-]([A-Z][a-z]*)[\s-]([0-9]{4,4})$/i";
$clean[]   = "\\3-\\2-\\1";

$pattern[] = "/^([A-Z][a-z]*)[\s-]([0-9]{4,4})$/";
$clean[]   = "\\2-\\1-01";

$foo = preg_replace($pattern, $clean, $verb_date);

If I were you, I'd write several regexes, one for each date format you wish to recognize. It makes the regexes much easier to read, and you can still write sub-expressions for catching e.g. months and then reuse those in your main regexes.



/Per Jessen

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux