替换符号奇怪的情况

foreach($ret as $object)
{
    $res = $object->...;
    $img_src = $res[0]->src;
    echo $img_src . '<br />';
    echo str_replace("&size=2", "", $img_src) . '<br /><br />';
}

$img_src ~ 'http://site.com/img.jpg&size=2'

And I have to receive same link but without &size=2. Why doesn't work my last line in code. It shows the same url.

Are you absolutely certain there are any goofy unprintable characters in your source string? Try debugging with this:

printf("%s
", join(':', str_split($img_src)));

And make sure you really have &size=2 in your string. If you see two consecutive colons, you've got something like a \0 or some other character mucking up the works in the middle of your string.

Seems to work on this end:

http://site.com/img.jpg&size=2 
http://site.com/img.jpg

from

<?php
$img_src = 'http://site.com/img.jpg&size=2';
echo $img_src.'<br />';
echo str_replace("&size=2", "", $img_src).'<br/><br/>';
?>

use preg_replace:

$c=preg_replace("/&size=2/","",$img_src);

Example of usage

<?php
$sr="http://site.com/img.jpg&size=2";
echo preg_replace("/&size=2/","",$sr);
?>

This will output

http://site.com/img.jpg