折影轻梦
文章60
标签46
分类8
Typecho文章字数计算

Typecho文章字数计算

炒鸡简单的,只需要在当前使用的主题的根目录的 functions.php 插入如下代码

当前仅仅统计文章中的中文字数。

function  art_count ($cid){
$db=Typecho_Db::get ();
$rs=$db->fetchRow ($db->select ('table.contents.text')->from ('table.contents')->where ('table.contents.cid=?',$cid)->order ('table.contents.cid',Typecho_Db::SORT_ASC)->limit (1));
$text = preg_replace("/[^\x{4e00}-\x{9fa5}]/u", "", $rs['text']);
echo mb_strlen($text,'UTF-8');
}

在需要引用的地方插入

<?php art_count($this->cid); ?>
本文作者:折影轻梦
本文链接:https://nexmoe.com/131.html
版权声明:本文采用 CC BY-NC-SA 3.0 CN 协议进行许可
×