Home > Backend Development > PHP Tutorial > 【100分求助】xml_parse_into_struct 函数解析XML,中文乱码

【100分求助】xml_parse_into_struct 函数解析XML,中文乱码

WBOY
Release: 2016-06-23 14:01:42
Original
1223 people have browsed it

测试代码如下:

$xmldata = '<?xml version="1.0" encoding="UTF-8"?><description>中文</description>';$parser = xml_parser_create ('UTF-8');$vals = array();xml_parse_into_struct ($parser, $xmldata, $vals);xml_parser_free ($parser);print_r($vals);
Copy after login


PHP版本为5.4.20

转换结果中,中文部分为乱码。

请教下大家,有没有哪位遇到过这个问题,如何解决……谢谢!


回复讨论(解决方案)

显然你的程序文件时 gbk 的
$xmldata = '中文';
$xmldata = iconv('gbk', 'utf-8', $xmldata);

其实你iconv转码也是可以的 
但是我这边显示是正常的没有乱码 估计是浏览器的编码不对

显然你的程序文件时 gbk 的
$xmldata = '中文';
$xmldata = iconv('gbk', 'utf-8', $xmldata);

唔……我刚才查了一下,程序文件的编码格式是以UTF-8无BOM格式编码,如果我将其转为UTF-8编码,就可以正常显示中文了……

多谢帮助,确实是文件编码格式的问题!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template