PHP regular intercepts all containing strings, PHP regular extracts all pictures in the string, and replaces!

$preg = '//i';// Regular expression matching img tag

$preg2 = '/background-image:[ ]?url\("[\'"]?(.*?\.(?:png|jpg|jpeg|gif))/i';//The url that matches the background the regular expression of

$value = '

';

preg_match_all($preg, $value, $allImg);//This matches all img

preg_match_all($preg2, $value, $allImg2);//This matches all background img

$imgList = array_merge($allImg[1],$allImg2[1]);

if (empty($imgList)){undefined

return false;

}

$imgList = array_unique($imgList);

$newImgList = [];

$flag = false;

foreach ($imgList as $key=>$img_url){undefined

echo $img_url.PHP_EOL;

print_r("The {$key} picture...".PHP_EOL);

$newImgList[] = $img_url.'[update flag]';

}

print_r('All images are processed in a loop!'.PHP_EOL);

echo str_replace($imgList,$newImgList,$value);

Related: PHP regular intercepts all containing strings, PHP regular extracts all pictures in the string, and replaces!