Answer the question
In order to leave comments, you need to log in
Why does the encoding problem occur when using the simplexml_load_file function?
Good afternoon. Please help me with this issue.
There is an xml file in windows-1251 encoding, I import the file using the simplexml_load_file php function, I display the resulting result on the page. Everything is fine with the Latin alphabet, but the Cyrillic alphabet is displayed in krakozyabry (Портфель).
The site also works in windows-1251 encoding.
Tell me, please, what could be the problem and how to overcome it. I've been battling with it for a few days now.
PS I understand that the site in windows-1251 encoding is bad manners.
Answer the question
In order to leave comments, you need to log in
It’s clear about the encoding of the xml file, but what about the encoding on the page where you display data? Open the code view and in the head you will see what encoding the page is in.
simplexml runs on top of libxml, which does not support windows-1251 by default.
xmlsoft.org/encoding.html#Default
At the same time, if iconv is available, then after parsing the file you will get strings in utf-8
php.net/manual/en/ref.simplexml.php#79258
• try echo iconv("UTF- 8", "windows-1251", $text_from_simple_xml)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question