Strlen()在修剪标题时显示错误字符


strlen() shows wrong character when trim the title wordpress

strlen显示错误字符,当在标题的末尾是ë它显示"…"

是我的代码:

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

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

将上面的行重写为

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