strlen() shows wrong character when trim the title wordpress

strlen showing wrong character when at the end of the title is ë its showing “�…”

The is my code:

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

Related posts

Leave a Reply

1 comment

  1. For unicode characters you need to use mb_strlen() and mb_substr()

    Rewrite the above line to

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