Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 12-23-2003, 01:06 PM   #1 (permalink)
Epsilon
Regular Contributor
 
Epsilon's Avatar
 
Join Date: Mar 2003
Location: Las Vegas, NV
Posts: 127
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
Old 12-23-2003, 02:37 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,489
sde is on a distinguished road
i was going to mention something about escaping the backslahs before the 's', however i notice this forum does weird things with 2 backslashes. =/
__________________
Mike
sde is offline   Reply With Quote
Old 12-23-2003, 02:38 PM   #3 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
if you want perl-style regular expressions, see preg()

had you looked at the ereg documentation on php.net (http://us4.php.net/manual/en/function.ereg.php) you would have already known this.
joe_bruin is offline   Reply With Quote
Old 12-23-2003, 11:26 PM   #4 (permalink)
Epsilon
Regular Contributor
 
Epsilon's Avatar
 
Join Date: Mar 2003
Location: Las Vegas, NV
Posts: 127
Epsilon is on a distinguished road
Quote:
Originally posted by joe_bruin
if you want perl-style regular expressions, see preg()

had you looked at the ereg documentation on php.net (http://us4.php.net/manual/en/function.ereg.php) you would have already known this.
Thank you joe_bruin. You could have just directed me to the page without being a pretentious **********, but you took the extra time to point out that I'm stupid for using this forum to ask for advice. You are correct, if I had seen that document previously I would have already known this. Then I wouldn't have had to waste your valuable time with such a trivial question.

With people of your impressive calibur trolling the threads it's a wonder these forums don't get more posts.

Thanks again, so much. Truly appreciated. Really.
__________________
--Epsilon--
Epsilon is offline   Reply With Quote
Old 12-24-2003, 12:52 AM   #5 (permalink)
Epsilon
Regular Contributor
 
Epsilon's Avatar
 
Join Date: Mar 2003
Location: Las Vegas, NV
Posts: 127
Epsilon is on a distinguished road
Hmph.
__________________
--Epsilon--
Epsilon is offline   Reply With Quote
Old 12-24-2003, 07:36 AM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,489
sde is on a distinguished road
elipson, .. we welcome you here, ... and respect your opinion, ... but name calling doesn't do anything for our community.

your point was made even with my minor edit.. feel free to delete your post if you feel that you can not make your point without that word, but please don't re-edit my edit!

thanks
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Comes of Age sde Code Newbie News 0 04-14-2004 11:41 AM
I need to learn PHP Nitro PHP 9 06-28-2003 11:24 AM
regular expressions - extract a string sde PHP 1 06-16-2003 03:05 PM
Php Vs. Asp sde PHP 6 06-06-2003 06:02 PM
Time Regular Expressions abc123 All Other Coding Languages 2 06-12-2002 02:39 PM


All times are GMT -8. The time now is 01:22 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting