#48330 [Opn->Bgs]: preg_replace() Pattern Modifiers 'e' Bug

From: Date: Tue, 19 May 2009 14:39:31 +0000
Subject: #48330 [Opn->Bgs]: preg_replace() Pattern Modifiers 'e' Bug
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-137506@lists.php.net to get a copy of this message
ID: 48330 Updated by: jani@php.net Reported By: seateng at sohu dot com -Status: Open +Status: Bogus Bug Type: PCRE related Operating System: Redhat AS5 PHP Version: 5.2.9 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2009-05-19 13:51:59] 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> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48330&edit=1

« previous php.bugs (#137506) next »