Page 1 of 1

Two different syntax works the same way...

Posted: Wed Dec 13, 2006 5:47 am
by kaisellgren
Hi all,

I can't notice any differences with these codes

Code: Select all

preg_match("/\\[/",$str);
and

Code: Select all

preg_match("/\[/",$str);
They are returning same results. The both match character [ literally. What's the difference?

Posted: Wed Dec 13, 2006 7:31 am
by feyd
Technically, the second is incorrect syntax, however they end up being the same thing to PCRE. This is due to PHP parsing backslashes as standard escape characters, then PCRE parsing them again. If you wish to have a backslash in the pattern use four of them.

Posted: Wed Dec 13, 2006 7:56 am
by kaisellgren
Ah ok thank you. :)