thinkphp

获取文章内第一张图片做为ThinCMF缩略图

获取文章内第一张图片做为ThinCMF缩略图

10月19日 09:33 小刀 2455 


在application/Common/Common/funtion.php中添加函数:spl_post_thumb()

1.2.3.4.5.6.7.8.9.10.11.
function spl_post_thumb($content){
    $pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/"; 
    preg_match_all($pattern,$content,$matchContent); 
    if(isset($matchContent[1][0])){ 
        $temp=$matchContent[1][0]; 
        return $temp;
    }else{ 
        $temp="./images/no-image.jpg";//如何文章内没有图片,此处可以改为你设好的系统默认图地址 
        return $temp;
    } 
}

这样就可以在模版中直接调用此函数了。

原文连接:http://b.voyog.com/index.php/article/index/id/17/cid/8.html

CMF交流群:10432283


联系我们

13823142866

在线咨询: 点击这里给我发消息

邮件:chawuzhai@163.com

工作时间:周一至周五,8:30-18:30,节假日休息

QR code