How to fix special characters when the title or excerpt is shortened
I have this code for the title
<?php $thetitle = $post->post_title; $getlength = strlen($thetitle); $thelength = 26; echo substr($thetitle, 0, $thelength); if ($getlength > $thelength) echo "..."; ?>
And this for the excerpt
<?php $content = get_the_content(); $content = strip_tags($content); echo substr($content, 0, 89); ?>...
Everything works correctly, except when the last letter is a special character, because then I get this � (Malformed byte sequence).