Domanda

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; ?>
È stato utile?

Soluzione

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')."...";
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top