You are here: Re: formatting time « PHP Programming Language « IT news, forums, messages
Re: formatting time

Posted by Rik on 10/13/04 11:46

Mark wrote:
> D excellent. then I just need the first letter after each integer,
> and
> the rest should be easy.
> thank you.

preg_match_all("/([0-9]+)[\s]*([a-zA-Z]?)/i",$input,$matches);

Regex workbench explains it like this:

Capture
Any character in "0-9"
+ (one or more times)
End Capture
Any character in "\s"
* (zero or more times)
Capture
Any character in "a-zA-Z"
? (zero or one time)
End Capture

Matching: 3h
0 => 3h
1 => 3
2 => h
Matching: 3 hours
0 => 3 h
1 => 3
2 => h
Matching: 3 hrs
0 => 3 h
1 => 3
2 => h
Matching: 3h5min
0 => 3h
1 => 3
2 => h
0 => 5m
1 => 5
2 => m
Matching: 3hrs5 minutes6s
0 => 3h
1 => 3
2 => h
0 => 5 m
1 => 5
2 => m
0 => 6s
1 => 6
2 => s

But still... typos can be made, what if someone types "5hours 6ninutes"? How
are you going to interpret "n", which is next to both "h" and "m"?
I still think it shouldn't be done this way, but hey, it's your call

Grtz,
--
Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация