Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 替换符号奇怪的情况 foreach($ret作为$object) { $res=$object->。。。; $img_src=$res[0]>src; echo$img_src.“”; echo str_replace(“&size=2”,”,$img_src)。“”; }_Php_String_Replace_Str Replace - Fatal编程技术网

Php 替换符号奇怪的情况 foreach($ret作为$object) { $res=$object->。。。; $img_src=$res[0]>src; echo$img_src.“”; echo str_replace(“&size=2”,”,$img_src)。“”; }

Php 替换符号奇怪的情况 foreach($ret作为$object) { $res=$object->。。。; $img_src=$res[0]>src; echo$img_src.“”; echo str_replace(“&size=2”,”,$img_src)。“”; },php,string,replace,str-replace,Php,String,Replace,Str Replace,$img\u src~'http://site.com/img.jpg&size=2“ 我必须接收相同的链接,但没有&size=2。为什么我的最后一行代码不起作用。它显示相同的url。似乎在这方面起作用: foreach($ret as $object) { $res = $object->...; $img_src = $res[0]->src; echo $img_src . '<br />'; echo str_replace("&a

$img\u src
~
'http://site.com/img.jpg&size=2“


我必须接收相同的链接,但没有
&size=2
。为什么我的最后一行代码不起作用。它显示相同的url。

似乎在这方面起作用:

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


使用预更换:

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

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

您是否绝对确定源字符串中有任何愚蠢的不可打印字符?尝试使用以下命令进行调试:

http://site.com/img.jpg

并确保字符串中确实有&size=2。如果你看到两个连续的冒号,你就有一个类似于A 0或其他字符的东西在你的字符串中间拼凑作品。

相同的位置,两条线输出相同的URL(有和大小=2)在你的服务器上工作吗?如果是,请将答案标记为正确,以便其他人遵循。
h:t:t:p:::/:/:m:d:a:t:a::y:a:n:d:e:e:x::n:e:t:/:i:?:p:a:t:h:=:b:0:1:0:0:8:2:4:u:L:G:-:-:G:0:9:L:h::j:p:G:&:a:m:p:;:我明白了。有
&;大小=2
好吧,这是你的答案。您应该查找的字符串不是“&size=2”,而是“&;size=2”。(如果是这样的话,请别忘了将我的答案标记为已接受。);)
<?php
$sr="http://site.com/img.jpg&size=2";
echo preg_replace("/&size=2/","",$sr);
?>
http://site.com/img.jpg
printf("%s\n", join(':', str_split($img_src)));