ID: 41235 User updated by: alexey at gmail dot com Reported By: alexey at gmail dot com -Status: Open +Status: Closed Bug Type: *Search functions Operating System: linux PHP Version: 4.4.6 New Comment:
Oh well. Thanks for your explanation. Closed. Previous Comments: ------------------------------------------------------------------------ [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
