PHP获取html内容中的所有图片或第一张图片地址

<?php
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 '';
}
0
0

发表回复

Your email address will not be published. Required fields are marked *.

*
*