dedecms统计当前文章的字数

在/include/extend.func.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)'/}

例如:方圆建筑圆模板网详细页面的代码为:

<div class="content" id="content">
                <h1>{dede:field.title/}</h1>
                <div class="art_info"><span>发布时间:{dede:field.pubdate function="MyDate('Y-m-d H:i:s',@me)"/}</span> <span>编辑:{dede:field.writer/}</span> <span>来源:{dede:field.source/}</span> <span>阅读:{dede:field name='suiji' runphp='yes'}@me = (rand(50,999));{/dede:field}次</span><div class="keyword">关键字:{dede:field.keywords/}</div></div>
                <div class="article" id="content">
                    <p class="daodu">导读:本文是由{dede:field.writer/}于{dede:field.pubdate function="MyDate('Y-m-d H:i:s',@me)"/}发布的关于<a href="http://www.sdfymb.com{dede:field name='arcurl'/}">{dede:field.keywords/}</a>的资讯,其主要内容为:{dede:field.description runphp='yes'}if(@me<>'' )@me = @me;{/dede:field.description}</p>
                    <p class="tongji"><span>本文字数:{dede:field.body function='strlen_utf8(@me)'/}字</span><span>预计阅读耗时:{dede:field.body function='strtime_utf8(@me)'/}分钟</span><span>推荐咨询客服:<a rel="nofollow" href="/contactus.html" target="_blank">在线客服</a> <a rel="nofollow" href="/contactus.html" target="_blank">获取报价</a></span></p>
                    {dede:field.body/}
                    <div class="tag">本文标签:{dede:field.id function="GetTagsFLink(@me,' ')"/}</div>
<div class="shara"><div class="bdsharebuttonbox"><a rel="nofollow" href="#" class="bds_more" data-cmd="more">分享到:</a><a rel="nofollow" href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间">QQ空间</a><a rel="nofollow" href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博">新浪微博</a><a rel="nofollow" href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博">腾讯微博</a><a rel="nofollow" href="#" class="bds_renren" data-cmd="renren" title="分享到人人网">人人网</a><a rel="nofollow" href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信">微信</a></div>
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{"bdSize":16}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script></div>
                    <div class="txt-upDown">
                        <p>{dede:prenext get='pre'/}</p>
                        <p>{dede:prenext get='next'/}</p>
                    </div>

猜你喜欢

转载自blog.51cto.com/14201330/2450200