Rumah > Artikel > pembangunan bahagian belakang > php里的str_replace函数可以与此同时替换3处吗
php里的str_replace函数可以同时替换3处吗?
$content = str_replace('#p#副标题#e#','',$body);
$content = str_replace('请看下一页', '',$body);
$content = str_replace('/uploads', 'http://www.****.com/uploads',$body);
各位,我想输出的$body读取的内容,同时替换掉里面的“#p#副标题#e#” “'请看下一页” “/uploads”
请问怎么实现呀?现在只能替换最后一个语句的,3个不能同时被替换
------解决思路----------------------
$body =<<< 'TXT'<br />各位,我想输出的$body读取的内容,同时替换掉里面的“#p#副标题#e#” “'请看下一页” “/uploads”<br />TXT;<br /><br />$body = str_replace('#p#副标题#e#','',$body);<br />$body = str_replace('请看下一页', '',$body);<br />$body = str_replace('/uploads', 'http://www.****.com/uploads',$body);<br />echo $body;<br />写成这样更简捷
body =<<< 'TXT'<br />各位,我想输出的$body读取的内容,同时替换掉里面的“#p#副标题#e#” “'请看下一页” “/uploads”<br />TXT;<br />$p = array('#p#副标题#e#', '请看下一页', '/uploads');<br />$r = array('','', 'http://www.****.com/uploads');<br />echo str_replace($p, $r, $body);
<br />header("Content-type: text/html; charset=utf-8");<br />$body = <<<BODY<br />#p#副标题#e#<br />请看下一页<br />/uploads<br />BODY;<br />//$content = str_replace('#p#副标题#e#','',$body);<br />//$content = str_replace('请看下一页', '',$body);<br />//$content = str_replace('/uploads', 'http://www.****.com/uploads',$body);<br />echo "替换前的内容:" . "<br/>" . $body . "<br/>" . "<hr/>";<br />$arr_orignal_content = array ('#p#副标题#e#', '请看下一页', '/uploads');<br />$arr_replace_content = array ('', '', 'http://www.baidu.com/uploads');<br />$body = str_replace($arr_orignal_content, $arr_replace_content, $body);<br />echo "替换后的内容:" . "<br/>" . $body;<br />
<br />$content = str_replace('#p#副标题#e#','',$body);<br />$content = str_replace('请看下一页', '',$content);<br />$content = str_replace('/uploads', 'http://www.****.com/uploads',$content);<br />