$text = "内容<img src = 'http://www.test.com/test1.jpg' height='100' width='100'>内容
内容2<img data-id='test' src='http://www.test.com/hello.png' height='100' width='100'>内容2";
$preg = '#<img(.+?)src\s*=\s*[\"|\']([^"|^\']+?)[\"|\']([^>]*?)>#';
$text = preg_replace_callback($preg,function ($matches){
$replace = 'http://www.test.com/test2.jpg';//要替换的src
return "<img{$matches[1]}src=\"$replace\"{$matches[3]}>";
}, $html);
PHP-正则匹配文章图片标签src的内容并替换
最新推荐文章于 2022-10-22 22:29:57 发布