P
P
Peter2014-05-22 11:50:07
PHP
Peter, 2014-05-22 11:50:07

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"]);

I get:
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

Where to look? What could be the problem?
ps. it is worth adding, probably, a DB screen:
32dea37664244148a7b5b63d1dedfda7.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ruslan72, 2014-05-22
@Alcospb

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';");

or substitute the desired one instead of utf8

P
Pavel Solovyov, 2014-05-22
@pavel_salauyou

have you tried converting the file to utf-8 using mb_convert_encoding?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question