On 15/03/11 2:18 AM, Martin Scotta wrote:
I chose the simplest example to show the preg_replace behavior,
You've GOT to be kidding. The SIMPLEST?! How about an example that doesn't require escaping ALL the interesting characters involved? Here's a modified version that I think it quite a bit simpler: <?php function test($str) { static $re = '/(^|[^a])b/'; static $change = '$1ab'; echo $str, PHP_EOL; // input echo preg_replace($re, $change, $str), PHP_EOL, PHP_EOL; // output } test("str bb str"); // bug? test("str abab str"); // ok test("b str b"); // ok test("ab str ab"); // ok ?> The way I interpret it, it should put an 'a' before every 'b' that is not already preceded by an 'a'. But the buggy case gives 'str abb str' rather than the expected 'str abab str'. It does look like a bug to me. Ben.
there are better (and safer) ways to scape slash characters. Anyways, *is this the expected preg_replace behavior?* Martin <?php function test($str) { static $re = '/(^|[^\\\\])\'/'; static $change = '$1\\\''; echo $str, PHP_EOL, preg_replace($re, $change, $str), PHP_EOL, PHP_EOL; } test("str '' str"); // bug? test("str \\'\\' str"); // ok test("'str'"); // ok test("\'str\'"); // ok ---- Expected: str '' str str \'\' str str \'\' str str \'\' str 'str' \'str\' \'str\' \'str\' ---- Result: str '' str str \'' str str \'\' str str \'\' str 'str' \'str\' \'str\' \'str\' Martin Scotta
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php