Edit report at https://bugs.php.net/bug.php?id=61214&edit=1

 ID:                 61214
 Updated by:         ras...@php.net
 Reported by:        58219758 at qq dot com
 Summary:            puzzled replace when replacement contains "="
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            PCRE related
 Operating System:   windows 7
 PHP Version:        5.3.10
 Block user comment: N
 Private report:     N

 New Comment:

This is not a bug. '=' has special meaning in ?= and ?<= expressions and it is 
on 
the list of characters quotes by preg_quote.


Previous Comments:
------------------------------------------------------------------------
[2012-03-01 08:25:13] 58219758 at qq dot com

Description:
------------
$search = array('/required/','/min\=(\d+)/','/max\=(\d+)/','/\w+\=([^=]+)/',);
$replace2 = array('R=1','R="$1"','R="$1"',);
It seems doesn't work correctly when replacement contains "="

Test script:
---------------
$search = array('/required/','/min\=(\d+)/','/max\=(\d+)/','/\w+\=([^=]+)/',);
$replace1 = array('R1','R"$1"','R"$1"',);
$replace2 = array('R=1','R="$1"','R="$1"',);
$replace3 = array('R\\=1','R\\="$1"','R\\="$1"',);
$from = 'required min=3 max=5 code=code';
echo preg_replace($search, $replace1, $from);
echo preg_replace($search, $replace2, $from);
echo preg_replace($search, $replace3, $from);

Expected result:
----------------
R1 R"3" R"5"
R=1 R="3" R="5"
R\=1 R\="3" R\="5"

Actual result:
--------------
R1 R"3" R"5"
 ="3" =code
R\=1 R\="3" R\="5"


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



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

Reply via email to