|
Posted by Al on 08/29/05 17:32
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.
[Back to original message]
|