Question

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; ?>
Was it helpful?

Solution

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')."...";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top