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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: stas at metalinfo dot ru
New email:
PHP Version: OS:

 

 [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 15:01:31 2024 UTC