note 86957 added to function.preg-replace
| From: | janezr at osu1 dot php dot net | Date: | Wed, 12 Nov 2008 11:31:18 +0000 |
| Subject: | note 86957 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-146416@lists.php.net to get a copy of this message | ||
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
----
Server IP: 69.147.83.197
Probable Submitter: 86.61.77.143
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/86957
Del: integrated -- https://master.php.net/note/delete/86957/integrated
Del: useless -- https://master.php.net/note/delete/86957/useless
Del: bad code -- https://master.php.net/note/delete/86957/bad+code
Del: spam -- https://master.php.net/note/delete/86957/spam
Del: non-english -- https://master.php.net/note/delete/86957/non-english
Del: in docs -- https://master.php.net/note/delete/86957/in+docs
Del: other reasons-- https://master.php.net/note/delete/86957
Reject -- https://master.php.net/note/reject/86957
Search -- https://master.php.net/manage/user-notes.php