Home >Backend Development >PHP Tutorial >PHP regular match replace image address

PHP regular match replace image address

PHP中文网
PHP中文网Original
2017-03-30 15:52:392351browse

PHP正则匹配替换图片地址:

网上能找到很多匹配图片src的正则表达式和替换的实例,都是然并卵,不能马上解决问题。

只是要找到src里的那一段给替换掉就行了。

给一段内容:

$content = '';

正则匹配替换:

preg_replace("/()/is","\${1}asdf\${3}",$content);

$content只要是一个PHP regular match replace image address标签里的全部内容就可以,将src里的内容单独圈起来,前后的内容都整个的包括起来,${1}和${3}就是src的前后内容,将src替换成想要的就行。

以上就介绍了PHP正则匹配替换图片地址,包括了方面的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Statement:
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