How to replace src in img with regular expression in php

藏色散人
Release: 2023-03-03 20:58:01
Original
2842 people have browsed it

php用正则替换img src的方法:首先打开相应的PHP文件;然后添加正则内容为“preg_replace('/(How to replace src in img with regular expression in php)/i'...”并保存即可。+src=\>

How to replace src in img with regular expression in php

推荐:《PHP视频教程

具体问题:

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

<img width="197" height="253" alt=" " src="/case/clxy/page/files/newspic/20090928084704364888.jpg" border="0" />
Copy after login

我要将其中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('/()/i',"\${1}\${3}",$url);
echo $ok;
Copy after login

替换后的结果为

<img width="197" height="253" alt=" " src="/files/newspic/20090928084704364888.jpg" border="0" />
Copy after login

The above is the detailed content of How to replace src in img with regular expression in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template