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 编码
基础教程推荐
- 如何替换eregi() 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
