Re: preg_match

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

 



Jasper Bryant-Greene wrote:
> John Nichel wrote:
> 
>> Personally, I have never used \\ in PCRE when looking for things like
>> spaces (\s), word boundraries (\b), etc. and it's all worked out fine.
> 
> 
> It will work fine, but only because those (\s and \b) just happen to not
> be special characters in PHP *at this time*.
> 
> It's sloppy programming because the backslash is known to be a special
> character, and \s or \b could conceivably become special characters at
> some time in the future. It's unlikely, but possible.
> 
> Not only that, but it makes it more likely that you'll forget and put \n
> when you meant \\n, \r when you meant \\r, \t when you meant \\t, and so
> on...

Also people thinking that PHP's single-quoted strings don't have any
escape sequences run into trouble when they have backslash as the last
character of the string:

$path = 'c:\';

This will give you parse error because the parser would think that you
wanted literal ' character and looks in vain for the string end. The
correct line should be:

$path = 'c:\\';

Edin

-- 
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