|
Posted by Edin Kadibašić on 10/20/13 11:24
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
Navigation:
[Reply to this message]
|