Php 查找所有html<;img>;标签,并由其他人替换?
有一个变量$result包含HTML页面 例如:Php 查找所有html<;img>;标签,并由其他人替换?,php,html,Php,Html,有一个变量$result包含HTML页面 例如: <p>Text</p> <img src="http://test.com/img.png" alt="Some text"> <p>Other text</p> <img src="http://test.com/img.png" alt="Some text"> 文本 其他文本 我需要这个变量($result)来创建更改标记,同时保持页面的完整性: 是: <p
<p>Text</p>
<img src="http://test.com/img.png" alt="Some text">
<p>Other text</p>
<img src="http://test.com/img.png" alt="Some text">
文本
其他文本
我需要这个变量($result)来创建更改标记,同时保持页面的完整性:
是:
<p>Text</p>
<img src="http://test.com/img.png" alt="Some text">
<p>Other text</p>
<img src="http://test.com/img.png" alt="Some text">
其中src=“原始图像”
需要:
其中src-图像加载和数据src-图像取自旧的src
如何解析html并使用php进行必要的更改?请看一看
可能类似的方法会奏效:
$returnValue = preg_replace('#<img(.*?)src="(.*?)"(.*?)>#', '<img$1src="http://test.com/loading.png" data-source="$2"$3>', $result)
$returnValue=preg#u replace(“##,”,“$result)
你用谷歌搜索过吗。。。?