How to fix special characters when the title or excerpt is shortened
Question
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).
0
4 weeks
2022-12-31T14:48:33-05:00
2022-12-31T14:48:33-05:00 0 Answers
0 views
0
Leave an answer