PHP encoding with DOMDocument(使用 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 编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 DOMDocument 进行 PHP 编码


基础教程推荐
- 在多维数组中查找最大值 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01