Home > Backend Development > PHP Problem > How to replace image link in php

How to replace image link in php

藏色散人
Release: 2023-03-13 11:04:02
Original
2840 people have browsed it

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;;
Copy after login

正则匹配替换:

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

$content只要是一个标签里的全部内容就可以,将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!

Related labels:
php
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