Answer the question
In order to leave comments, you need to log in
How to solve encoding problems?
Greetings.
Situation following:
I receive XML from Yandex api. mb_detect_encoding writes ASCII I
write to the database.
I tried 2 options:
a) parse XML into objects and write each one separately
b) write the entire xml
I tried to write to two different databases on different hostings.
I constantly experience problems with encoding.
The current state of this:
Wrote all the xml in the database.
$response = $app["dbs"]['local'] -> fetchAssoc("SELECT response FROM api_response WHERE id = '" . $max_id["max(id)"] . "'");
$data = new SimpleXMLElement($response["response"]);
ning: SimpleXMLElement::__construct(): Entity: line 163: parser error : Input is not proper UTF-8, indicate encoding ! Bytes: 0xD0 0x3F 0xD0 0x9A in .../src/api.php on line 189
Answer the question
In order to leave comments, you need to log in
After connecting to the database:
mysql_query("SET NAMES 'utf8';");
mysql_query("SET CHARACTER SET 'utf8';");
mysql_query("SET SESSION collation_connection = 'utf8_general_ci';");
have you tried converting the file to utf-8 using mb_convert_encoding?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question