N
N
Nikolai Novosad2015-03-24 16:23:11
PHP
Nikolai Novosad, 2015-03-24 16:23:11

From xml(utf-8) to db(cp-1251)?

Hello.
There is data in the xml file in utf-8 encoding. Parsed xml in php and inserted into the database.
But when I had to insert it into the database with the cp-1251 encoding, the bugs started.
Through Notepad I changed the encoding, and chose to use 'ANSI' - all the same, only krakozyabry.
How to get rid of krakozyabr?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
FanatPHP, 2015-03-24
@FanatPHP

set names utf8

D
Dmitry Bay, 2015-03-24
@kawabanga

how do you parse xml?

C
Centrino, 2015-03-24
@Centrino

You need to convert the data to the format of your database, because Cyrillic characters in ANSI, UTF-8 and CP-1251 are different.

$data = { parse xml}
foreach ($data as $key => $value) {
         if (!mb_check_encoding($value, 'Windows-1251')) {
                    $data[$key] = mb_convert_encoding($value, 'UTF-8', 'Windows-1251');
          }
}
{insert data to $db}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question