Display funny characters after text substr () with accent marks
I am using substr () function to cut strings. It worked fine with a normal string, but in the case of a string with accent marks, it displayed funny characters before the cut like so:
Here is the code:
$rawtitle ="Tin đăng của giangvy1011 tin của dtdd";
$title = substr($rawtitle,0,36).'...';
echo $title;
Here is the result I got for echo:
Is there a way to get around this or another feature to archive this? Many thanks
+3
source to share
1 answer
substr is not multibyte. A character ủ
is represented by more than a byte. With substr, you truncate these byte sequences and corrupt the string.
You need to use mb_substr instead .
+6
source to share