匹配的图像链接不包含空格

时间:2013-01-03 04:46:08

标签: php preg-match-all

  

可能重复:
  Matching images links containing spaces

我的代码是:

preg_match_all('#(?:<\>]+href=\")?(?:http://)?(http(s?)://([^\s]*)\.(jpg|gif|png))#',$imagelinks, $group_imagelink);
echo $group_imagelink[1][0];
 echo $group_imagelink[1][1];

和内容是(换行,最初是一行):

  

$imagelinks = "http://www.site.com/images/img.jpghttp://site.com/2011/06/img.jpghttp://site.org/en/thumb/e/ec/img.jpghttp://site.com/wp-content/uploads/2010/12/img.jpghttp://www.site.com/assets/resources/2006/09/Civilization-3-0001.jpghttp://www.site.com/fr/images/screenshots/img.jpghttp://site.com/wp-content/gallery/img.jpghttp://site.com/images/G/01/software/detail-page/img.jpg";

有人可以帮助我拥有一个正确的pregmatch所有提取第一,第二等...文本与图像和空格的链接。

1 个答案:

答案 0 :(得分:1)

这种模式可以满足您的需求:

#(.+?(jpg|gif|png))#

它会给你:

0 =&gt;   数组(
    0 =&gt; 'http://www.site.com/images/img.jpg',
    1 =&gt; 'http://site.com/2011/06/img.jpg',
    2 =&gt; 'http://site.org/en/thumb/e/ec/img.jpg',
    3 =&gt; 'http://site.com/wp-content/uploads/2010/12/img.jpg',
    4 =&gt; 'http://www.site.com/assets/resources/2006/09/Civilization-3-0001.jpg',
    5 =&gt; 'http://www.site.com/fr/images/screenshots/img.jpg',
    6 =&gt; 'http://site.com/wp-content/gallery/img.jpg',
    7 =&gt; 'http://site.com/images/G/01/software/detail-page/img.jpg',

您还可以在此网站上测试preg_match,节省大量时间:Functions Online