求替换全局img图片的正则表达式
如题
现在有一字符串是
$content = '
test
';<br /><br /> public static function replace_img_publish_path($content){<br /> $pattern='/(<[img|IMG].+src=\"?.+)(images\/tmp\/)(.+\.(jpg|gif|bmp|bnp|png)\"?.+>)/';<br /> $replacement="\${1}images/pub/\${3}";<br /> print preg_replace($pattern, $replacement, $content);<br /> exit;<br /> }<br /><br />
test
$content = '<p><img src="http://localhost:8080/story/images/tmp/1403530150545.jpg" style="max-width:90%" alt="求轮换全局img图片的正则表达式" ><img src="http://localhost:8080/story/images/tmp/1403530147265.jpg" style="max-width:90%" alt="求轮换全局img图片的正则表达式" >test</p>';<br /><br />$content = preg_replace('#(?<=src="http://localhost:8080/story/images/)tmp/#', 'pub/', $content);<br />echo $content;
pub/1403530150545.jpg" style="width: 268px;">pub/1403530147265.jpg" style="width: 268px;">test
<br />$content = '<p><img src="http://localhost:8080/story/images/tmp/1403530150545.jpg" style="max-width:90%" alt="求轮换全局img图片的正则表达式" ><img src="http://localhost:8080/story/images/tmp/1403530147265.jpg" style="max-width:90%" alt="求轮换全局img图片的正则表达式" >test</p>';<br /><br />replace_img_publish_path($content);<br /><br />function replace_img_publish_path($content){<br /> $pattern='/(<[img<br><font color='#FF8000'>------解决方案--------------------</font><br>IMG].+src=\"?.+)(images\/tmp\/)(.+\.(jpg<br><font color='#FF8000'>------解决方案--------------------</font><br>gif<br><font color='#FF8000'>------解决方案--------------------</font><br>bmp<br><font color='#FF8000'>------解决方案--------------------</font><br>bnp<br><font color='#FF8000'>------解决方案--------------------</font><br>png)\"?.+>)/U';<br /> $replacement="\${1}images/pub/\${3}";<br /> print preg_replace($pattern, $replacement, $content);<br /> exit;<br />}<br />
test