Re: regular expression for time

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

 



babu wrote:
HI,
how can i write regular expression for time in 24-hour format i:e, HH:MM:SS. using preg_match. thanks
babu

		
---------------------------------
How much free photo storage do you get? Store your holiday snaps for FREE with Yahoo! Photos. Get Yahoo! Photos

You need to be more specific about:

What is before and after the time string.  It's probably white-space. That so?

Can your HH, values be without the leading zero, e.g., 2:12:15.

Can you be certain that MM and SS will be included. If the time is entered by users, they can get lazy and give you "2", for example.

Given the simplest case. $pattern= "%\s(\d\d:\d\:\d\d)\s%"; ["%" is simply the delimitor, it can be almost any thing.] The \s is optional, it says white-space.

$num= preg($pattern, $string [,$match_array]) $time_value= $match_array[1]; $num of matches in case you want to test for none or more than 1.

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