Typecho 获取文章图片数量代码
时间:4年前 阅读:8280
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).'' ; ?>
主要原理就是正则来获取图片判断几个图片
网友评论