php获取内容中的所有图片

时间:2018-06-15 23:11:42 类型:PHP
字号:    

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 '';  
    }
dump(getImgs($content));


如果存在的话, 返回