<?php
$html="<img src=http://www.baidu.com/img/logo.gif >kuhkjhj<img src=<img src=http://www.baidu.com/img/logo45.gif >";
preg_match_all("/(src|src)=[\"|'| ]{0,}(http:\/\/(.*?)\.(gif|jpg|jpeg|bmp|png))/",$html,$out);
$arrLink = $out[2];
die($arrLink[0]);
?>非贪婪匹配

解决方案 »

  1.   

    <?php
    $html="<img src=http://www.baidu.com/img/logo.gif >kuhkjhj<img src=<img src=http://www.baidu.com/img/logo45.gif >";
    preg_match_all("/(src|src)=[\"|'| ]{0,}(http:\/\/(.*?)\.(gif|jpg|jpeg|bmp|png))/",$html,$out);
    $arrLink = $out[2];
    die($arrLink[0]);
    ?>非贪婪匹配
      

  2.   

    非贪婪匹配 学习了,但这个模式下,有些特例域名下就不行,
    gif|jpg|jpeg|bmp|png 这些域名如 www.gif.com, www.jpg.net