废话不多说,先上代码
/*
* $content 文章内容
* $order 要获取哪张图片,ALL所有图片,0第一张图片
*/
function getImgs($content,$order=\'ALL\')
{
$pattern = \"/<img .*?src=[\\\'|\\\"](.*?(?:[\\.gif|\\.jpg]))[\\\'|\\\"].*?[\\/]?>/\";
preg_match_all($pattern,$content,$match);
if(isset($match[1]) && !empty($match[1])){
if($order===\'ALL\'){
return $match[1];
}
if(is_numeric($order) && isset($match[1][$order])){
return $match[1][$order];
}
}
return \'\';
}
运行结果:
© 版权声明
THE END
暂无评论内容