typecho获取文章阅读时间代码

实例代码:(放到functions.php文件里面)

//文章阅读时间统计
function art_time ($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']);
    $text_word = mb_strlen($text,'utf-8');
    echo ceil($text_word / 400);
}

获取代码为

阅读时长 ≈ <?php echo art_time($this->cid); ?>分钟
文章由官网发布,如若转载,请注明出处:https://www.veimoz.com/73
2 条评论
5.1k

发表评论

已有 2 条评论

  1. jclser     Win 7 /    FireFox
    2020-04-19 18:30

    你这个好像只匹配中文,推荐这个和word统计一致的? 不用另做查询,post.php已经做好查询了,直接调用就好。
    function art_time ($contents) {
    省略……
    }
    转自https://boke112.com/3845.html

    1. 【管理员】Vv     Win 7 /    Chrome
      2020-04-20 07:32

      @jclser

      大概看了一下你推荐的,还真有点意思:真棒::真棒:

!