日期:2014-05-17  浏览次数:20494 次

正则批量替换
$str ='<img src="test/aaa/a.jpg" widht=33 height=3><img src="f/aaa/a.jpg" widht=4 height=3>'

如何批量将src前面加个域名呢

$str ='<img src="http://xxxx.com/test/aaa/a.jpg" widht=33 height=3><img src="http://xxxx.com/f/aaa/a.jpg" widht=4 height=3>'

------解决方案--------------------
引用:
引用:$str = '<img src="test/aaa/a.jpg" widht=33 height=3><img src="f/aaa/a.jpg" widht=4 height=3>';
$str = str_replace('src="', 'src="http://www.xxx.com/', $str);
echo $……


能不用则不用 这是原则...


$str = '<img src="test/aaa/a.jpg" widht=33 height=3><img src="f/aaa/a.jpg" widht=4 height=3>';
echo preg_replace('/(src=")/', "$1'http://www.xxx.com/", $str);