Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 查找所有html<;img>;标签,并由其他人替换?_Php_Html - Fatal编程技术网

Php 查找所有html<;img>;标签,并由其他人替换?

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

有一个变量$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>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)

你用谷歌搜索过吗。。。?