Typecho文章字数统计

Typecho文章字数统计

Tod
Tod
2023-09-23 / 0 评论 / 9 阅读 / 正在检测是否收录...

  在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); ?>
0

评论 (0)

取消