如何在字符串中编辑<img/>标记

时间:2015-01-24 08:42:45

标签: php html codeigniter

<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p><img src="../../../..//js/uploads/images/selva.png" alt="" /></p>
<p>we are checkng our website</p>
<p>kfoaskf</p>
<p>asldfjas</p>
<p>jasdklfk'sd</p>
<p><img src="../../../..//js/uploads/images/images.jpg" alt="" /></p>

这是我的字符串值。我需要改变这一点 <img src="../../../..//js/uploads/images/images.jpg"><img src="js/uploads/images/images.jpg">

对于每个图像,我需要修改路径。 怎么做?我的字符串值每次都不同

1 个答案:

答案 0 :(得分:2)

试试这个兄弟

$str='<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p><img src="../../../..//js/uploads/images/selva.png" alt="" /></p>
<p>we are checkng our website</p>
<p>kfoaskf</p>
<p>asldfjas</p>
<p>jasdklfk\'sd</p>
<p><img src="../../../..//js/uploads/images/images.jpg" alt="" /></p>';
echo str_replace("../../../..//js/uploads/images/images.jpg","/js/uploads/images/images.jpg",$str);