Edit report at https://bugs.php.net/bug.php?id=61214&edit=1
ID: 61214 Comment by: 58219758 at qq dot com Reported by: 58219758 at qq dot com Summary: puzzled replace when replacement contains "=" 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: $search = array( '/required/', '/min\=(\d+)/', '/max\=(\d+)/', '/\w+\=([^=]+)/', ); $replace2 = array( 'R=1', 'R="$1"', 'R="$1"', ); in this case, the result is still ="3" =code Previous Comments: ------------------------------------------------------------------------ [2012-03-01 09:59:23] 58219758 at qq dot com "=" will be quoted to "\=", in this case, the result is R\=1 R\="3" R\="5" too, whenever "\=" or "\\=". ------------------------------------------------------------------------ [2012-03-01 08:35:04] ras...@php.net This is not a bug. '=' has special meaning in ?= and ?<= expressions and it is on the list of characters quotes by preg_quote. ------------------------------------------------------------------------ [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