php get the body all pictures

Code

/**
 * Notes:获取文本中所以图片
 * @auther: xxf
 * Date: 2019/7/25
 * Time: 13:55
 * @param $content
 * @param int $order 第几张,0全部
 * @return array
 */
function getImages($content,$order=0){
    $pattern="/<img.*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png|\.jpeg|\.?]))[\'|\"].*?[\/]?>/";
    preg_match_all($pattern,$content,$match);
    if(!empty($match[1])){
        if($order == 0){
            return $match[1];
        }
        if(!empty($match[1][$order-1])){
            return $match[1][$order-1];
        }
    }
    return [];
}

 

Published 85 original articles · won praise 45 · views 950 000 +

Guess you like

Origin blog.csdn.net/flysnownet/article/details/97259079