View Single Post
Old 12-23-2003, 02:06 PM   #1 (permalink)
Epsilon
Regular Contributor
 
Epsilon's Avatar
 
Join Date: Mar 2003
Location: Las Vegas, NV
Posts: 131
Epsilon is on a distinguished road
PHP Regular Expressions

I thought PHP used standard POSIX regular expressions. Is this wrong? I used the following code to populate a drop-down list with the intention of excluding any element in the array $sites that contained a space:
Code:
while ($array_cell = each($sites))
{
   if (!ereg("\s",$array_cell[value]))
   {
      print ("<option value=\"".strtolower($array_cell[value])."\"$selected>".$array_cell[value]."</option>\n");
   }
}
I'm used to Perl where \s matches any whitespace character. But in PHP this code literally matched a lowercase s character -- not cool.

I replaced the regular expression with:
Code:
!ereg(" ",$array_cell[value])
and it properly matched spaces, but I'm concerned about the reliability of this method. There are other ways to make a space aside from ASCII code 32 (pressing the space bar). Could this cause a problem? Is there a REGEXP symbol in PHP that will match ANY whitespace as there is in Perl?
__________________
--Epsilon--
Epsilon is offline   Reply With Quote