Reply to Re: [PHP] preg_match

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация