使用 DOMDocument 进行 PHP 编码 [英] PHP encoding with DOMDocument

查看:19
本文介绍了使用 DOMDocument 进行 PHP 编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<tag>
Алекс М
</tag>

当我尝试使用 DOMDocument 函数获取以下代码的内容时,它返回如下内容:

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).

推荐答案

尝试:

$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);

这篇关于使用 DOMDocument 进行 PHP 编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆