$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);