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, "&amp;\\1", $data);
echo $data."\n";

//
http://search.networkworld.com/index.html?col=&amp;qs=&qc=&amp;si=0&ql=a&amp;nh=25&amp;lk=1&rf=0qqqqqqqqqqqq

$data=ereg_replace($pattern, "&amp;\\1", $data);
echo $data."\n";

//
http://search.networkworld.com/index.html?col=&amp;qs=&amp;qc=&amp;si=0&amp;ql=a&amp;nh=25&amp;lk=1&amp;rf=0qqqqqqqqqqqq

?>


Expected result:
----------------
http://search.networkworld.com/index.html?col=&amp;qs=&amp;qc=&amp;si=0&amp;ql=a&amp;nh=25&amp;lk=1&amp;rf=0qqqqqqqqqqqq

Actual result:
--------------
http://search.networkworld.com/index.html?col=&amp;qs=&qc=&amp;si=0&ql=a&amp;nh=25&amp;lk=1&rf=0qqqqqqqqqqqq


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=41235&edit=1

Reply via email to