Home > Backend Development > PHP Tutorial > 请大家帮小弟我看看这个截取网址的正则有关问题在哪?感谢

请大家帮小弟我看看这个截取网址的正则有关问题在哪?感谢

WBOY
Release: 2016-06-13 12:07:44
Original
884 people have browsed it

请大家帮我看看这个截取网址的正则问题在哪?感谢

本帖最后由 liao3bafa 于 2014-10-10 13:34:29 编辑 我需要取出以http开头的所有图片的地址,写了这个正则 
$regstr = 'http://.*(\.jpg|\.png|\.gif)'
使用函数匹配 preg_match_all($regstr, $strtest2, $match);对 strtest2这个字符串能顺利取出图片的地址,但对于strtest1这样的字符串却无法取出,请大家帮我看看问题出在哪儿,感谢 

$strtest1 = 'e7342287f1485896249c474049d5317c:1:0:|http://img01.taobaocdn.com/bao/uploaded/i1/T1dNrmFEJaXXXXXXXX_!!0-item_pic.jpg;78e4591d5b18775a71912801623c0d26:1:1:|http://img01.taobaocdn.com/bao/uploaded/i1/1643666761/TB2aMrfaFXXXXbGXpXXXXXXXXXX_!!1643666761.jpg;';

$strtest2 = '请大家帮小弟我看看这个截取网址的正则有关问题在哪?感谢';

------解决思路----------------------
用下面这种吧
<?php<br /><br /><br />$strtest1 = 'e7342287f1485896249c474049d5317c:1:0:<br><font color='#FF8000'>------解决思路----------------------</font><br>http://img01.taobaocdn.com/bao/uploaded/i1/T1dNrmFEJaXXXXXXXX_!!0-item_pic.jpg;78e4591d5b18775a71912801623c0d26:1:1:<br><font color='#FF8000'>------解决思路----------------------</font><br>http://img01.taobaocdn.com/bao/uploaded/i1/1643666761/TB2aMrfaFXXXXbGXpXXXXXXXXXX_!!1643666761.jpg;';<br /><br />$strtest2 = '<a href="http://www.williamlong.info/cat/?tags=Programming" :<br><font color='#FF8000'>------解决思路----------------------</font><br>rel="tag"><img  src="17c:1:0:<br alt="请大家帮小弟我看看这个截取网址的正则有关问题在哪?感谢" ><font color='#FF8000'>------解决思路----------------------</font><br>http://img01.taobaocdn.com/bao/uploaded/i1/T1dNrmFEJaXXXXXXXX_!!0-item_pic.jpg" alt="研发" class="thumb" /></a>';<br /><br />$regstr = '/http:\/\/img.*(?:\.jpg<br><font color='#FF8000'>------解决思路----------------------</font><br>\.png<br><font color='#FF8000'>------解决思路----------------------</font><br>\.gif)/U';<br /><br />preg_match_all($regstr, $strtest1, $match);<br /><br />var_dump($match);<br /><br />preg_match_all($regstr, $strtest2, $match);<br /><br />var_dump($match);<br /><br /><br />?>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template