PHP提取页面第一张图为缩略图的代码

2019PHP高薪工程师学习路线图....>>>

<?php
$p = '/<img.*?src=[\'|\"](.+?)[\'|\"].*?>/i';
preg_match_all($p,$str,$match);
print_r($match[1][0]);
?>

<img alt="" src="http://usr.im/200x60?bg=3498DB&text=tool.lu" class="img" />
结果为:http://usr.im/200x60?bg=3498DB&text=tool.lu
 
<img alt="" src="http://img.mukewang.com/user/55c877240001291602790279-80-80.jpg" class="img" />
结果为:http://img.mukewang.com/user/55c877240001291602790279-80-80.jpg