note 86957 deleted from function.preg-replace by thiago
| From: | thiago@php.net | Date: | Wed, 12 Nov 2008 12:20:36 +0000 |
| Subject: | note 86957 deleted from function.preg-replace by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-146419@lists.php.net to get a copy of this message | ||
Note Submitter: janezr
----
The /.../e modifier is a bit tricky (as stated above). Extra steps must be taken to unescape
everything. I may be mistaken but I thought that in some older version of PHP "" used to
unescape \' also...
Example:
<?php
$str1 = "/.../e will escape all ', \" and \\ in \\1 thru \\9. The problem is
because \"\" properly unescapes all but \' - hence extra str_replace!";
$str2 = preg_replace( "/^(.*)$/e",
"str_replace('\\\\\\\\\\'','\\'',\"\\1\")", $str1
);
print( $str1 == $str2 );
?>
Could this be done with any less complication? Also there are so many backslashes. No less than 8
are needed to get one but I am sure that 4 should be enough.
PHP Version 5.1.6