ホームページ >バックエンド開発 >PHPチュートリアル >グローバル画像画像を回転するための正規表現を見つける
求替换全局img图片的正则表达式
如题
现在有一字符串是
$content = 'e388a4556c0f65e1904146cc1a846bee0e4d0c951fae79d695fe284eeecf208f3f71f10d81d479ca44ffa56cb45c2308test94b3e26ee717c64999d7867364b1b4a3';
想要将这字符里面的 images/tmp 都替换成 images/pub
本人已经写了一个函数
<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 />
$content = '<p><img src="http://localhost:8080/story/images/tmp/1403530150545.jpg" style="width: 268px;"><img src="http://localhost:8080/story/images/tmp/1403530147265.jpg" style="width: 268px;">test</p>';<br /><br />$content = preg_replace('#(?<=src="http://localhost:8080/story/images/)tmp/#', 'pub/', $content);<br />echo $content;e388a4556c0f65e1904146cc1a846bee5d689a0ae00dc0e89f6140a925ce804e5c3666b7af2339cab5d50019c984abe0test94b3e26ee717c64999d7867364b1b4a3
<br />$content = '<p><img src="http://localhost:8080/story/images/tmp/1403530150545.jpg" style="width: 268px;"><img src="http://localhost:8080/story/images/tmp/1403530147265.jpg" style="width: 268px;">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 />