php的str_replace一个问题

来源:百度知道 编辑:UC知道 时间:2024/06/27 16:20:59
$content = str_replace("width","width=\"480\"",$content);
这段是有效的

$content = str_replace("width=\"390\"","width=\"480\"",$content);
这段却没有效果

$content都有匹配的内容
请问为什么呢
如果代码有错的话
那怎么将width="390"替换成width="480"呢
谢谢了啊,菜鸟,不太了解

想必你是搞错了,程序有效
<?php
$content = 'width="390",width="480",,,';
$content = str_replace("width=\"390\"","width=\"480\"",$content);
echo $content;
?>
输出:
width="480",width="480",,,

你仔细看看你的程序,应该是没错的

$content = preg_replace("width=\"390\"","width=\"480\"",$content);

原因很简单
$content = str_replace("width","width=\"480\"",$content);
结果为$content="width=480";
后$content = str_replace("width=\"390\"","width=\"480\"",$content);
不知道 "width=390"在哪?如果拼写没错误的话
$content = str_replace("width=\"480\"","width=\"390\"",$content);
是肯定没问题的