|
Posted by Robin Vickery on 08/23/05 13:06
On 8/23/05, Jasper Bryant-Greene <jasper@bryant-greene.name> wrote:
> Robin Vickery wrote:
> > Both of these will fail to compile:
> > preg_match( '/\\7abc/', $myString);
> > preg_match( '/\7abc/', $myString);
> >
> > Both of these are fine:
> > preg_match( '/\\abc7/', $myString);
> > preg_match( '/\abc7/', $myString);
> >
> > In fact they behave *exactly* as if you hadn't doubled them up. You've
> > not achieved anything, but you've made your regexp just a little more
> > difficult to read and maintain.
>
> You achieved something. You made your code syntactically correct, even
> if PHP lets you get away with things like \a inside single-quoted strings..
They are both syntactically correct. Which is why you don't get a
syntax error for either of them.
As the manual explicitly says in section on single-quoted strings:
http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single
"usually there is no need to escape the backslash itself."
"variables and escape sequences for special characters will not be
expanded when they occur in single quoted strings."
There's no need to invent syntactic rules just to make life difficult.
-robin
Navigation:
[Reply to this message]
|