Home > Backend Development > PHP Tutorial > 求1正则,替换img标签的src属性

求1正则,替换img标签的src属性

WBOY
Release: 2016-06-13 12:25:59
Original
823 people have browsed it

求一正则,替换img标签的src属性
如题,我的$data['content']里有很多内容,其中也有img标签:
求1正则,替换img标签的src属性


我想得到把src属性里的/Uploads/去掉,其他的保存不变。正则一直不怎么会,求大神告诉我怎么过滤,谢谢

------解决思路----------------------

<br />preg_replace('`src="/Uploads/([^"]+?)"`','src="$1"',$data['content']);<br />
Copy after login

------解决思路----------------------
^ 除了 “ 都匹配,+ 至少一个,? 非贪婪(尽可能少的)匹配

就是匹配到后面正常的链接(相当于用 ” 来做匹配的结束),用$1表示捕获到的内容
------解决思路----------------------
 [^"] 不是 " 的所有字符 
+? 非贪婪匹配

用在这里多余了

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