preg_match_all ('/http:.*?\.png|http:.*?\.gif/', $buffer, $array);因为.* 可以匹配任何字符 默认时,数量符是“贪吃型”(greedy)的,即会在不导致剩余模式失败的情况下尽可能多地匹配(直到所允许的数目上限)。

解决方案 »

  1.   

    preg_match_all ('/http:[^:]*\.png|http:[^:]*\.gif/', $buffer, $array);
      

  2.   


    $buffer = 'http://a/images/quote.png) no-repeat 0px 0px;padding:0px 0px 5px 23px;background:url(http://b/images/quote_small.gif';
    preg_match_all ('/http:\/\/([^)]+)/', $buffer, $array);
    foreach( $array[0] as $key => $value){
        echo "<a href='$value' target='_blank'>" . $value . "<br />";
    }
      

  3.   


    $buffer = 'http://a/images/quote.gif) no-repeat 0px 0px;padding:0px 0px 5px 23px;background:url(http://b/images/quote_small.gif';
    preg_match_all ('/http:.*\.png|http:.*\.gif/siU', $buffer, $array);
    foreach( $array[0] as $key => $value){
        echo "<a href='$value' target='_blank'>" . $value . "<br />";
    }