php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49508 encoding problems with preg_replace
Submitted: 2009-09-09 07:48 UTC Modified: 2009-09-09 08:57 UTC
From: stas at metalinfo dot ru Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.2.10 OS: Debian Lenny
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:
MUST BE VALID
Solve the problem:
34 - 21 = ?
Subscribe to this entry?

 
 [2009-09-09 07:48 UTC] stas at metalinfo dot ru
Description:
------------
preg_replace changes replaced string encoding when replacement parameter is double quoted.

Reproduce code:
---------------
$source = 'asdfasd asdf asdf [company=456[replacement]] asdf';
echo preg_replace('~\[\s*company=([0-9]+)\[\s*([^\]]+\s*)\]\]~', '\2', $source);
echo preg_replace('~\[\s*company=([0-9]+)\[\s*([^\]]+\s*)\]\]~', "\2", $source);

Expected result:
----------------
asdfasd asdf asdf replacement asdf
asdfasd asdf asdf replacement asdf

Actual result:
--------------
asdfasd asdf asdf replacement asdf
asdfasd asdf asdf  asdf

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-09 08:57 UTC] jani@php.net
\?is escape char inside double quotes. If you use double quotes, you need to escape the escape char: "\\1"


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 08:01:29 2024 UTC