|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-05-19 13:51 UTC] seateng at sohu dot com
Description:
------------
preg_replace() Pattern Modifiers 'e' Bug
Reproduce code:
---------------
<?php
$html_body = '<a href="#">asdf</a>';
echo preg_replace("/(<\/?)(\w+)([^>]*>)/e",
"'\\1'.strtoupper('\\2').'\\3'",
$html_body);
?>
Expected result:
----------------
<A href="#">asdf</A>
Actual result:
--------------
<A href=\"#\">asdf</A>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 31 23:00:01 2025 UTC |
RTFM: When using the e modifier, this function escapes some characters (namely ', ", \ and NULL) in the strings that replace the backreferences. This is done to ensure that no syntax errors arise from backreference usage with either single or double quotes (e.g. 'strlen(\'$1\')+strlen("$2")'). Make sure you are aware of PHP's string syntax to know exactly how the interpreted string will look like.