Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/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图像标记中的图像源,并排除某些图像_Php - Fatal编程技术网

Php 替换HTML图像标记中的图像源,并排除某些图像

Php 替换HTML图像标记中的图像源,并排除某些图像,php,Php,我有以下代码 $body = preg_replace('/<img(.*?)src="(.+)"/Ui','<img src="renderImage.php?image=\\2&width=<?=$img_width?>&url=<?=$mobiURL?>"',$body); $body=preg_replace('/&url=“”,$body); $body包含一个包含img标记的整个html页面,上面的代码工作得很好,但是我需要排除

我有以下代码

$body = preg_replace('/<img(.*?)src="(.+)"/Ui','<img src="renderImage.php?image=\\2&width=<?=$img_width?>&url=<?=$mobiURL?>"',$body);
$body=preg_replace('/&url=“”,$body);
$body包含一个包含img标记的整个html页面,上面的代码工作得很好,但是我需要排除带有字符串maps.google的图像,这样它就不会被替换

有没有办法做到这一点

方法#1: 而不是改变正则表达式并使其更复杂。 您可以改用preg\u replace\u回调

在回调函数中,您可以忽略maps.google.com图像

方法#2:

  • 首先使用maps.google.com src使IMG标记无效。 例如,将
    标记转换为


    可能重复的也请参见@Gordon-无重复,我不需要知道如何解析HTML,我知道上面的方法不正确,但我不能只修改现有代码。请定义
    我不能只修改
    …(你正在修改它)说服你的老板!!!(当然有一个可行的解决方案)我改变了整个代码,但我也尝试了你的解决方案,你的解决方案也成功了,我接受你的答案