最完美的匹配网页中图片 src 部分的正则表达式

时间:2023-12-17 16:15:14
$str='<p style="padding: 0px; margin-top: 0px; margin-bottom: 0px; line-height: 200%;"><img border="0" src="upfiles/2009/07/1246430143_4.jpg" alt=""/></p><p style="padding: 0px; margin-top: 0px; margin-bottom: 0px; line-height: 200%;"><img border="0" src=\'upfiles/2009/07/1246430143_3.jpg\' alt=""/></p><p style="padding: 0px; margin-top: 0px; margin-bottom: 0px; line-height: 200%;"><img border="0" src="upfiles/2009/07/1246430143_1.jpg" alt=""/><img width="280" height="187" alt="" class="imgloading" original="http://s.yoututuan.com/team/2011/1206/13231497847660.jpg" src="http://s.yoututuan.com/team/2011/1206/13231497847660.jpg" style="display: block; ">';

    $pattern="/<img.*?src=['|\"](.*?(?:\.(?:gif|jpg)))['|\"].*?[\/]?>/i";
preg_match_all($pattern,$str,$match); echo '<pre>';
print_r($match);