Home  >  Article  >  Backend Development  >  PHP正则匹配查看原图,该怎么解决

PHP正则匹配查看原图,该怎么解决

WBOY
WBOYOriginal
2016-06-13 11:45:511062browse

PHP正则匹配查看原图
哪位高手帮忙写个正则匹配内容:
$str='内容内容内
容内容内容内容内容内容PHP正则匹配查看原图,该怎么解决内容内容内容PHP正则匹配查看原图,该怎么解决';
匹配效果:
$str='内容内容内
容内容内容内容内容内容PHP正则匹配查看原图,该怎么解决原图内容内容内容PHP正则匹配查看原图,该怎么解决原图';
------解决方案--------------------

$str = '内容内容内<br />容内容内容内容内容内容<img  src="http:www.wz.com/1.jpg"   style="max-width:90%" height="100px;" / alt="PHP正则匹配查看原图,该怎么解决" >内容内容内容<img  src="http:www.wz.com/2.jpg"/ alt="PHP正则匹配查看原图,该怎么解决" >';<br /><br />echo preg_replace('/<img .*?src="([^"]+).*? alt="PHP正则匹配查看原图,该怎么解决" >/is', '$0<a href="$1">原图</a>', $str); 
内容内容内
容内容内容内容内容内容PHP正则匹配查看原图,该怎么解决原图内容内容内容PHP正则匹配查看原图,该怎么解决原图

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn