php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48330 preg_replace() Pattern Modifiers 'e' Bug
Submitted: 2009-05-19 13:51 UTC Modified: 2009-05-19 14:39 UTC
From: seateng at sohu dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.2.9 OS: Redhat AS5
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: seateng at sohu dot com
New email:
PHP Version: OS:

 

 [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>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-19 14:39 UTC] jani@php.net
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. 
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Sep 19 17:00:01 2025 UTC