Answer the question
In order to leave comments, you need to log in
PHP After substr, characters appear in the string � What is it?
I truncate the string substr , before that var_dump shows that it is a simple string without any characters.
But after, for example, in laravel , nothing was displayed through the blade . I broke my head why. But then I brought it out through echo and saw this there:
text text text �
How so? Where does it come from?
Answer the question
In order to leave comments, you need to log in
Perhaps you are cutting off the Cyrillic alphabet. It is better to use mb_substr for it. Because Cyrillic characters take up more space, and a regular substr can cut off half of the letter, which, of course, will not be displayed correctly.
Convert text from utf-8 to windiws-1251, cut text, then translate back (from windiws-1251 to utf-8)
$text='Строка';
$short = iconv('UTF-8','windows-1251',$text);
$short = substr($short ,0,2);
$short = iconv('windows-1251','UTF-8',$short );
echo $short;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question