Re: Problem with regular expressions

From: Date: Tue, 25 Jun 2002 11:32:02 +0000
Subject: Re: Problem with regular expressions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-103757@lists.php.net to get a copy of this message
Drew wrote: > When I run the following script it returns String Okay! when it should say > Invalid Characters Found. I've tried the script substituting $ for other > characters, such as j, and it works just fine. What do I need to do? > > <?php > > $input = "johnon@company.$com"; > > if (ereg("[$]", $input)) { > die("Invalid Characters Found."); > } elseif (ereg("[[:space:]]", $input)) { > die("Whitespace found."); > } else { > echo "String okay!"; > } > > ?> > > Thanks, > > Drew Try changing the double quotes to single quotes i.e. $input = 'johnon@company.$com'; php automatically attempts variable substitution on double-quoted strings, but not single-quoted strings. Unless you know that you want variable substitution, it's always safer and faster to use single-quotes. George

« previous php.general (#103757) next »