php怎么用正则替换img中src-LMLPHP

推荐:《PHP视频教程

具体问题:

正文中有多个这样的标签,如下

<img width="197" height="253" alt=" " src="/case/clxy/page/files/newspic/20090928084704364888.jpg" border="0" />
登录后复制

我要将其中src中的路径去掉开头的 "/case/clxy/page/"
是要正文中的所有的img标签都是要替换的。

实现方法:

这个还要写正则! 直接用DW 就可以批量替换了!

帮你写了一个

$url ='<img width="197" height="253" alt=" " src="/case/clxy/page/files/newspic/20090928084704364888.jpg" border="0" />';
$ok=preg_replace('/(<img.+src=\"?.+)(case\/clxy\/page\/)(.+\.\"?.+>)/i',"\${1}\${3}",$url);
echo $ok;
登录后复制

替换后的结果为

<img width="197" height="253" alt=" " src="/files/newspic/20090928084704364888.jpg" border="0" />
登录后复制

以上就是php怎么用正则替换img中src的详细内容,更多请关注Work网其它相关文章!

09-10 21:19