【问题标题】:PHP How can I get full image url by useing preg_match_allPHP 如何使用 preg_match_all 获取完整的图像 url
【发布时间】:2014-11-27 06:16:30
【问题描述】:

例如

$string = 
'aaaaaaasssssshttp://www.1.com/images/001/001/001/1.jpgddwxeaaaaaa
crewcwehttp://www.2.com/images/002/002/002/2.jpgrcegcger
cgwcgrewhttp://www.3.com/images/003/003/003/3.jpgcgergcer
cerggewrcgrewhttp://www.4.com/images/004/004/004/4.jpgecgewrcgerwcg
cerghttp://www.5.com/images/005/005/005/5.jpg';

我想得到第一个图像完整的网址,就像这样:

"http://www.1.com/images/001/001/001/1.jpg"

我使用了这个功能,但它不起作用

 if (preg_match_all('^http:\/\/\.(png|jpeg|jpg|gif|bmp)$/i', $string, $matches))

 print_r ($matches[1]);

谁能帮帮我?非常感谢!

【问题讨论】:

    标签: php regex image preg-match-all


    【解决方案1】:

    我已经测试了以下代码,它可以工作。它只捕获 jpg-url。

    $string = 
    'aaaaaaasssssshttp://www.1.com/images/001/001/001/1.jpgddwxeaaaaaa
    crewcwehttp://www.2.com/images/002/002/002/2.jpgrcegcger
    cgwcgrewhttp://www.3.com/images/003/003/003/3.jpgcgergcer
    cerggewrcgrewhttp://www.4.com/images/004/004/004/4.jpgecgewrcgerwcg
    cerghttp://www.5.com/images/005/005/005/5.jpg';
    
    preg_match_all("((http|https|ftp|ftps)://?([a-zA-Z0-9\\\./]*.jpg))", $string, $matches);
    
    print_r($matches[0][0]);
    

    【讨论】:

      猜你喜欢
      • 2021-10-29
      • 2013-04-06
      • 2018-08-28
      • 1970-01-01
      • 2011-09-04
      • 1970-01-01
      • 2011-10-09
      • 1970-01-01
      相关资源
      最近更新 更多