|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69672 preg_replace() does not necessarily cater to u modifier
Submitted: 2015-05-20 14:22 UTC Modified: 2015-06-05 15:04 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: Assigned:
Status: Duplicate Package: PCRE related
PHP Version: 5.6.9 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
23 - 12 = ?
Subscribe to this entry?

 [2015-05-20 14:22 UTC]
A user contributed note[1] mentions an "unexpected behavior" of
preg_replace() with regard to matching only an empty subpattern.
In my opinion, this is a bug, because UTF-8 encoded code points
must never be split when the u modifier is set. Matching for an
empty subpattern only might be regarded as a bug per se, but then
at least a warning should be raised or an error should be reported
by preg_last_error().

According to <> the current behavior has been
introduced with PHP 5.2.9, and is not directly related to the PCRE

[1] <>

Test script:

var_dump(preg_replace('/()/u', '*', "a\xc3\x84b"));


Expected result:
string(8) "*a*Ä*b*"

Actual result:
string(9) "*a*�*�*b*"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-05 15:04 UTC]
-Status: Open +Status: Duplicate
 [2015-06-05 15:04 UTC]
Duplicate of bug #53823.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 24 09:01:30 2024 UTC