正务库

Typecho 获取文章图片数量代码

时间:3年前   游览量:369    标签: nbsp    图片    获取    数量    quot    代码    文章   

Typecho 获取文章图片数量代码


做模板有些可能要显示一下文章下图片的数量,这就需要下面的代码了

/*
 * 获取图片数量
 * @since 2016.07.01
 **/
function hui_post_imgNum($content){
   $output =
   preg_match_all("/<img.?src="(.?)"1*>/i", $content,$matches);
   $cnt = count( $matches[1] );
       return $cnt;
}



调用方法:

<?php echo ''.hui_post_imgNum($this->content).'' ; ?>



主要原理就是正则来获取图片判断几个图片