Re: preg_match

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 8/23/05, Jasper Bryant-Greene <jasper@xxxxxxxxxxxxxxxxxx> 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

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux