#41235 [Com]: ereg_replace does not replace all occurrences
| From: | robinv at gmail dot com | Date: | Mon, 30 Apr 2007 09:33:18 +0000 |
| Subject: | #41235 [Com]: ereg_replace does not replace all occurrences | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-112074@lists.php.net to get a copy of this message | ||
ID: 41235
Comment by: robinv at gmail dot com
Reported By: alexey at gmail dot com
Status: Open
Bug Type: *Search functions
Operating System: linux
PHP Version: 4.4.6
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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