#49508 [Opn->Bgs]: encoding problems with preg_replace

From: Date: Wed, 09 Sep 2009 08:57:19 +0000
Subject: #49508 [Opn->Bgs]: encoding problems with preg_replace
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-142137@lists.php.net to get a copy of this message
 ID:               49508
 Updated by:       jani@php.net
 Reported By:      stas at metalinfo dot ru
-Status:           Open
+Status:           Bogus
 Bug Type:         PCRE related
 Operating System: Debian Lenny
 PHP Version:      5.2.10
 New Comment:

\ is escape char inside double quotes. If you use double quotes, you
need to escape the escape char: "\\1"




Previous Comments:
------------------------------------------------------------------------

[2009-09-09 07:48:35] 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


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=49508&edit=1



Thread (2 messages)

« previous php.bugs (#142137) next »