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

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

WBOY
Release: 2016-06-23 13:47:55
Original
920 people have browsed it

我需要取出以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$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 = '<a href="http://www.williamlong.info/cat/?tags=Programming" :|rel="tag"><img src="17c:1:0:|http://img01.taobaocdn.com/bao/uploaded/i1/T1dNrmFEJaXXXXXXXX_!!0-item_pic.jpg" alt="研发" class="thumb" /></a>';$regstr = '/http:\/\/img.*(?:\.jpg|\.png|\.gif)/U';preg_match_all($regstr, $strtest1, $match);var_dump($match);preg_match_all($regstr, $strtest2, $match);var_dump($match);?>
Copy after login

感谢,经测试可用

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