【问题标题】:strlen() shows wrong character when trim the title wordpress修剪标题wordpress时strlen()显示错误字符
【发布时间】:2014-05-05 09:29:50
【问题描述】:

strlen 在标题末尾显示错误字符时显示“...”

这是我的代码:

<?php $title = the_title('', '', false); 
$title = (strlen($title)<60) ? $title : substr($title,0,50)."...";
echo $title;
<?php endforeach; ?>

【问题讨论】:

    标签: php wordpress character-encoding char strlen


    【解决方案1】:

    对于 unicode 字符,您需要使用 mb_strlen()mb_substr()

    将上面一行改写为

    $title = (mb_strlen($title,'utf-8')<60) ? $title : mb_substr($title,0,50,'utf-8')."...";
    

    【讨论】:

    • 我收到此错误:警告:strlen() 只需要 1 个参数,2 在 /home/oranews/public_html/wp-content/themes/oranews/loop-single.php 第 44 行给出/跨度>
    • 我说mb_strlen()你为什么还在用strlen()
    • 我正在我的服务器上安装 mbstring 我希望这会有所帮助:)
    • 之后如果您有任何问题,请告诉我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-26
    • 1970-01-01
    • 2019-08-01
    • 1970-01-01
    • 2015-02-16
    相关资源
    最近更新 更多