Re: [PHP] preg_match and $ sign in PHP5

2005-09-05 Thread Jasper Bryant-Greene

Cabbar Duzayak wrote:

I have a regular expression check as:

preg_match("/$xyz/", $data, $matches);

And, as you know $xyz means "string starts with xyz". But somehow PHP
5 is interpreting this as variable xyz, and gives the  notice below.
You can ignore the message, but now it matches everything that has
xyz, i.e. aaxyzbb


Either use single quotes:

preg_match('/$xyz/', $data, $matches);

or escape the $-sign:

preg_match("/\$xyz/", $data, $matches);

--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

If you find my advice useful, please consider donating to a poor
student! You can choose whatever amount you think my advice was
worth to you. http://tinyurl.com/7oa5s

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match and $ sign in PHP5

2005-09-06 Thread Robin Vickery
On 9/6/05, Cabbar Duzayak <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> I have a regular expression check as:
> 
> preg_match("/$xyz/", $data, $matches);
> 
> And, as you know $xyz means "string starts with xyz". 

No it doesn't - "string starts with xyz" would be "/^xyz/" which
coincidentally avoids your problem of xyz being interpreted as a
variable name.

More generally, if you don't want $xyz interpreted as a variable, then
use single quotes - or if you must use double quotes, then escape the
$ with a backslash.

 -robin

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php