You are here: Re: Order of expression in preg_split « PHP Programming Language « IT news, forums, messages
Re: Order of expression in preg_split

Posted by d on 02/16/06 13:08

"none" <""krwl\"@(none)"> wrote in message
news:ML2dnQej5shzZG7eRVn-iA@rcn.net...
> Hello:
>
> Using PHP 4.3.11
>
> The line: $strDate = preg_split('/[\.\/-]/', $my_date);
> works to break apart a date in the form mm/dd/yyyy or mm.dd.yyyy or
> mm-dd-yyyy
> but the line: $strDate = preg_split('/[\/-\.]/', $my_date);
> doesn't work.
>
> Why does the order of the items make a difference?

In a regular expression character class definition (the bit in the []s), a
hyphen denotes a range of characters, so [a-z] will match all lowercase
letters of the alphabet, and [0-9] will match all numbers from 0 to 9. If
you escape your hyphen, it doesn't matter where you put it in your class.

$strDate = preg_split('/[\/\-\.]/', $my_date);

> Thanks,
>
> Ken

hope that helps!

dave

 

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

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