Re: regular expression for time
| From: | Al | Date: | Mon, 29 Aug 2005 14:32:40 +0000 |
| Subject: | Re: regular expression for time | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-221507@lists.php.net to get a copy of this message | ||
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! PhotosYou 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.