ID: 41235 Updated by: [EMAIL PROTECTED] Reported By: alexey at gmail dot com -Status: Closed +Status: Bogus Bug Type: *Search functions Operating System: linux PHP Version: 4.4.6
Previous Comments: ------------------------------------------------------------------------ [2007-04-30 11:15:53] alexey at gmail dot com The PHP manual does not specify the replacement order. What if we replace it from right to the left? This will give us a different answer. Also, the definition of a regular expression does not impose the evaluation order. Therefore, the right answer is to replace each occurrence of & in the original string with a &. ------------------------------------------------------------------------ [2007-04-30 11:05:12] alexey at gmail dot com Oh well. Thanks for your explanation. Closed. ------------------------------------------------------------------------ [2007-04-30 09:33:18] robinv at gmail dot com Not a bug: The pattern matches '&qs=&q' and replaces it with '&qs=&q'. It matches '&si=0&q' and replaces it with '&si=0&q'. It matches '&nh=25' and replaces it with '&nh=25' and it matches '&lk=1&' replacing it with '&lk=1&'. Which is exactly what you've told it to do. ------------------------------------------------------------------------ [2007-04-30 06:47:34] alexey at gmail dot com Description: ------------ ereg_replace() does not replace all occurrences of a regular expression as the following example shows. The pattern &([^;][^;][^;][^;][^;]) is replaced with &\\1 in a string http://search.networkworld.com/index.html?col=&qs=&qc=&si=0&ql=a&nh=25&lk=1&rf=0qqqqqqqqqqqq The output is http://search.networkworld.com/index.html?col=&qs=&qc=&si=0&ql=a&nh=25&lk=1&rf=0qqqqqqqqqqqq which indicates for example that the last & was not replaced. Reproduce code: --------------- <?php $data = "http://search.networkworld.com/index.html?col=&qs=&qc=&si=0&ql=a&nh=25&lk=1&rf=0qqqqqqqqqqqq"; $pattern="&([^;][^;][^;][^;][^;])"; $data=ereg_replace($pattern, "&\\1", $data); echo $data."\n"; // http://search.networkworld.com/index.html?col=&qs=&qc=&si=0&ql=a&nh=25&lk=1&rf=0qqqqqqqqqqqq $data=ereg_replace($pattern, "&\\1", $data); echo $data."\n"; // http://search.networkworld.com/index.html?col=&qs=&qc=&si=0&ql=a&nh=25&lk=1&rf=0qqqqqqqqqqqq ?> Expected result: ---------------- http://search.networkworld.com/index.html?col=&qs=&qc=&si=0&ql=a&nh=25&lk=1&rf=0qqqqqqqqqqqq Actual result: -------------- http://search.networkworld.com/index.html?col=&qs=&qc=&si=0&ql=a&nh=25&lk=1&rf=0qqqqqqqqqqqq ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=41235&edit=1
