PHP编码与DOMDocument [英] PHP encoding with DOMDocument
问题描述
<tag>
Алекс М
</tag>
当我尝试使用DOMDocument函数获取以下代码的内容时,它返回如下: / p>
When I try to get the content of the following code using DOMDocument functions, it returns something like:
ÐÐ»ÐµÐºÑ Ðœ
我尝试使用mb_convert_encoding,iconv和utf8_encode将DOMDocument编码设置为不同的值(UTF-8,ISO-8859-1),但没有成功。
I've tried setting DOMDocument encoding to different values (UTF-8, ISO-8859-1), using mb_convert_encoding, iconv and utf8_encode but without success.
如何获得АлексМ而不是ÐлÐμкÑÐœ?
How can I get "Алекс М" instead of "ÐÐ»ÐµÐºÑ Ðœ" ?
输入来自加载了curl的页面。当我输出页面内容到我的浏览器,字符显示正确(所以我怀疑输入是问题)。
The input is coming from a page loaded with curl. When I output the page content to my browser, the characters are displayed correctly (so I doubt the input is the problem).
推荐答案
> Try:
$string = file_get_contents('your-xml-file.xml');
$string = mb_convert_encoding($string, 'utf-8', mb_detect_encoding($string));
// if you have not escaped entities use
$string = mb_convert_encoding($string, 'html-entities', 'utf-8');
$doc = new DOMDocument();
$doc->loadXML($string);
这篇关于PHP编码与DOMDocument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!