织梦dede在文章页统计文章字数

找到文件/include/helpers/下面的文件extent.helper.php

在文件下面添加:

function strlen_utf8($str) {
    $i = 0;
    $count = 0;
    $str = Html2text($str);
    $len = strlen($str);
    while ($i < $len) {
        $chr = ord($str[$i]);
        $count++;
        $i++;
        if ($i >= $len) {
            break;
        }
        if ($chr & 0x80) {
            $chr <<= 1;
            while ($chr & 0x80) {
                $i++;
                $chr <<= 1;
            }
        }
    }
    return $count;
}

那么在文章页通过

{dede:field.body function='strlen_utf8(@me)'/}

即可实现当前文章字数的统计

例如:

<h3 class="minfo">
                本文由{dede:field.writer/}于{dede:field.pubdate function="MyDate('Y-m-d H:i:s',@me)"/}发布的来源于<a href="http://www.sdyuanmuban.com/">http://www.sdyuanmuban.com/</a>的字数为{dede:field.body function='strlen_utf8(@me)'/}个,标题为【{dede:field.title/}】的文章。其主旨内容为“{dede:field.description runphp='yes'}if(@me<>'' )@me = @me;{/dede:field.description}”等。
            </h3>

通过以上代码,我们便可以在dede文章页面实现作者、时间及本文字数的统计等功能。

猜你喜欢

转载自www.cnblogs.com/fymuban/p/10709701.html