[PHP] php seems to be inconsistent in its handling of backslashes ... maybe?
-- or maybe it's just the PCRE extension -- or quite likely I have got something wrong Hello members, I'm hoping you could enlighten me. Using error_reporting = E_ALL | E_STRICT, I tested the following statements: warning preg_match('#\\\#','any-string'); preg_match('##','any-string'); preg_match('#\#','any-string'); => warning preg_match('#\\#','any-string'); => warning preg_match('#\\\#','any-string'); ?> This seemed strange: warnings with 2 and 6 backlashes no warnings with 3, 7 warning with 5 but not with 3 and 7. The warning related of course to no matching delimeter '#' being found. So I wrote a little test script (preg.php) to test up to 10 backslashes: Here is the output: $ php preg.php - Number of '\' is 1 Pattern is: #\# error - Number of '\' is 2 Pattern is: #\\# ok - Number of '\' is 3 Pattern is: #\\\# error - Number of '\' is 4 Pattern is: ## ok - Number of '\' is 5 Pattern is: #\# error - Number of '\' is 6 Pattern is: #\\# ok - Number of '\' is 7 Pattern is: #\\\# error - Number of '\' is 8 Pattern is: ## ok - Number of '\' is 9 Pattern is: #\# error - Number of '\' is 10 Pattern is: #\\# ok End of output. This agrees with my understanding of backslash escaping (I hope that's right) but now I can't understand why I got the results earlier (shown in my first script). Many thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php seems to be inconsistent in its handling of backslashes ... maybe?
Richard Lynch wrote: warning This seemed strange: warnings with 2 and 6 backlashes For 2 backslashes, PHP "ate" the 2 backslashes, and handed PCRE #\#, and PCRE does not like that at all. Yet preg_match('#\\#','any-string'); does *not* throw a warning when I run the 2nd script - the one where I call it in the loop. no warnings with 3, 7 warning with 5 but not with 3 and 7. PHP and PCRE are doing their damndest to make sense of the garbage you typed, but if you type garbage, you get garbage. http://us.php.net/manual/en/language.types.string.php But PHP doesn't appear to be consistent. In the 2nd script, I *do* get warnings with 3 and 7 slashes. PHP can't be inconsistent. So there must be some semantic difference in my 2 scripts which unfortunately is eluding me. Cheers -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php seems to be inconsistent in its handling of backslashes ... maybe?
Al wrote: The proper way to handle special control PCRE characters like "\" is to use the hex [e.g., \x5C] value. Then you won't have a problem. The engine knows you want the the object treated as a character and an a control. That works nicely, thank you. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Best practices to ensure compatibility with PHP 6
Hi I'm would like to avoid PHP usages that are deprecated with regard to PHP 6. I would also like to code according to what is regarded as best practice. Are there any web resources that I can read to keep up to date? For instance: 1) safe_mode is deprecated. (The PHP manual gives me the answer) 2) Are named accessor/mutator methods recommended over the __get() and __set() magic methods? (A best practice question). Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best practices to ensure compatibility with PHP 6
Davi wrote: Em Domingo 22 Abril 2007 18:54, [EMAIL PROTECTED] escreveu: ... Have a look at PHP metting [1] and PHP-wiki [2]... =] [1] - http://www.php.net/~derick/meeting-notes.html [2] - http://oss.backendmedia.com/PhP60 Thank you for the links - it will get me started. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php