1 | <?php |
2 | $str = <<<EOF |
3 | <img src="uploads/images/20100318/20100318_1.gif"> |
4 | <img src="file/20100318_2.jpg"> |
5 | <img src="swfup/20100318_3.png"> |
6 | EOF; |
7 | echo '替换前:<pre>',htmlentities($str),'</pre><hr align=left width=320px/>'; |
8 | echo '替换后:<pre>',htmlentities(preg_replace('/(<img.+?src=")[^"]+(\/.+?>)/','$1file$2', $str)),'</pre>'; |
9 | ?> |
二、替换操做
替换前: php
替换后:
html
您可能感兴趣的文章:
php匹配图片地址的代码一例
PHP正则匹配日期和时间(时间戳转换)的例子
php匹配任何网址的正则表达式
PHP正则匹配获取URL中域名的代码
使用 preg_replace 函数 匹配图片并加上连接的方法
php用preg_match_all匹配文章中的图片
php正则表达式匹配URL中的域名 正则表达式