【发布时间】:2010-11-29 19:16:19
【问题描述】:
我正在寻找一个 PHP preg_replace() 解决方案找到图像的链接并将它们替换为相应的图像标签。
查找:
<a href="http://www.domain.tld/any/valid/path/to/imagefile.ext">This will be ignored.</a>
替换为:
<img src="http://www.domain.tld/any/valid/path/to/imagefile.ext" alt="imagefile" />
如果协议必须是 http://,.ext 必须是有效的图像格式(.jpg、.jpeg、.gif、.png、.tif),并且基本文件名变为 alt=""价值。
我知道 preg_replace() 是适合这项工作的函数,但我很喜欢正则表达式,所以非常感谢任何帮助!谢谢!
【问题讨论】:
标签: php regex preg-replace