获取文章内容的第一个图片

 public function getFirstImg($article)
    {
        $first_img = '';
        $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $article['article_content'], $matches);
        $first_img = $matches [1] [0];
        if (empty($first_img)) { //Defines a default image
            $first_img = SHOP_TEMPLATES_URL.'/images/newsimg.jpg';
        }
        return $first_img;
    }

 

posted @ 2017-05-08 17:01  伊苏克  阅读(283)  评论(0编辑  收藏  举报