php 获取正文所有图片或者第一张图

作者: cayman 分类: 编程技术 发布时间: 2019-03-17 22:37
function getImgs($content,$order='ALL'){
    $pattern='/<[img|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 '';
}

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注