)/is","\${1}asdf\${3}",$content);" can be replaced."/> )/is","\${1}asdf\${3}",$content);" can be replaced.">

Home  >  Article  >  Backend Development  >  How to replace image link in php

How to replace image link in php

藏色散人
藏色散人Original
2021-10-18 10:11:302837browse

php替换图片链接的方法:1、打开相应的PHP代码文件;2、通过正则表达式“preg_replace("/(How to replace image link in php)/is","\${1}asdf\${3}",$content);”替换即可。

How to replace image link in php

本文操作环境:windows7系统、PHP7.1版、DELL G3电脑

php怎么替换图片链接?

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

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

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

给一段内容:

$content = &#39;<img src="http://www.domainname.com/600_0_100_1/1439035192.4102/1e45426fe3d5410eedd45a82d9a0aead.jpg" rel="12375880" alt=""/>&#39;;

正则匹配替换:

preg_replace("/(<img .*?src=\")(.*?)(\".*?>)/is","\${1}asdf\${3}",$content);

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

推荐学习:《PHP视频教程

The above is the detailed content of How to replace image link in php. For more information, please follow other related articles on the PHP Chinese website!

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