Warning: getimagesize(): open_basedir restriction in effect. File(/etc/pki/tls/certs/ca-bundle.crt) is not within the allowed path(s): (/www/wwwroot/rinvay.cc/:/tmp/) in /www/wwwroot/rinvay.cc/usr/plugins/AMP/Action.php on line 469

Warning: failed loading cafile stream: `/etc/pki/tls/certs/ca-bundle.crt' in /www/wwwroot/rinvay.cc/usr/plugins/AMP/Action.php on line 469

Warning: getimagesize(): Failed to enable crypto in /www/wwwroot/rinvay.cc/usr/plugins/AMP/Action.php on line 469

Warning: getimagesize(https://www.rinvay.cc/img/logo.png): failed to open stream: operation failed in /www/wwwroot/rinvay.cc/usr/plugins/AMP/Action.php on line 469
Typecho 获取文章图片数量代码

Rinvay.H Blog

Typecho 获取文章图片数量代码

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

/<strong><em><em></em></em></strong><em><strong><em></em></strong></em><em>*</em>
* 获取图片数量
* @since 2016.07.01
**/
function hui_post_imgNum($content){
$output =
preg_match_all("/<img.<em>?src="(.</em>?)"<sup id="fnref-1"><a href="#fn-1" class="footnote-ref">1</a></sup>*>/i", $content,$matches);
$cnt = count( $matches[1] );
return $cnt;
}

调用方法:

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

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

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »