I
I
Ilyusha Prokopiev2016-12-06 00:04:15
PHP
Ilyusha Prokopiev, 2016-12-06 00:04:15

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

3 answer(s)
A
Andrey Inishev, 2016-12-06
@inish777

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.

E
Eugene, 2016-12-06
@Nc_Soft

Must use mb_** functions

D
Dmitry Ivaneychik, 2016-12-06
@DmitryIvaneychik

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 question

Ask a Question

731 491 924 answers to any question