Answer the question
In order to leave comments, you need to log in
Why is there an encoding error in php?
In a php program, a string is obtained using the POST method. When outputting a string, a echo($product)
normal Cyrillic string is displayed. But when outputting one character echo($product[0])
, we get this �. I also noticed that it strlen($product)
gives out the size twice the real one. What is the problem?
Answer the question
In order to leave comments, you need to log in
PHP does not have native support for utf-8, in which Cyrillic characters, for example, occupy two bytes. Use the functions from the mbstring extension.
Yes, you need to use mbstring, specifically for your case:echo mb_substr($product, 0, 1);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question