$str = '<img src="http://www.56ren.com/uploads/images/20100516000.jpg" height="120" width="120"><br />test1,. <img src="/uploads/images/20100516002.jpg" height="120" width="120"><br />test2, <img src="/uploads/images/20100516004.jpg" height="120" width="120"><br />test3,'; print "\n|"."****原串*****************************************************"."\n"; echo $str."\n"; print "\n"."\n"."**********替换后***********************************************"."\n"; //$parm = '/(<img.+src=\"?.+)(\"\/uploads\/)(.+\.(jpg|gif|bmp|bnp|png)\"?.+>)/i'; $parm = '/<img.+src=\"\/uploads\//'; //$replacy = array('${1}',"http://baidu.com/uc/upload",'${1}'); $replacy = 'http://baidu.com/uc/uploads/'; $re = preg_replace($parm,$replacy,$str,-1); print $re; print "\n"; echo $re[0]; print "\n";
转载于:https://my.oschina.net/osgrace/blog/920262