php simplexml_load_file 中文乱码的解决方法
中文乱码多半是编码导致的我们只要调整一下输出编码即可解决中文乱码问题,下面我们看simplexml_load_file中文乱码解决办法。
在PHP5.0 中,simplexml_load_file()是一个很好的读取和处理XML文件的函数,但是在读取和处理中文时会出现乱码,经过研究发现,如果是中文内容,必须经过iconv编码转换,否则显示为乱码。
代码如下 | 复制代码 |
$xml=simple_load_file('xml文件'); foreach($xml->soft as $temp){ echo $temp->name; //这就是软件名称了。 echo $temp->mem; //这就是软件说明了。 } |
英文正确中文乱码,这个我估计就是编码问题了。
后来网上找到了相关文章,如核心一句
1、如果xml的encoding与文件类型不符,立刻报错
2、simplexml可以处理gbk的XML,即文件内容和encoding都为gbk(ANSI格式)
3、不管文件内容是什么,处理完了,都是UTF8.
具体方法如下:
代码如下 | 复制代码 |
$chname = iconv('utf-8', 'gb2312', $table->param["name"]); |
实现将编码为'utf-8'的XML文件内容转换为 gb2312 格式的内容。
中文编码采用gb2312格式输出。
还有一种办法本人没测试过直接摊贩页面编码转成uft8
代码如下 | 复制代码 |
header("Content-type: text/html; charset=utf-8"); |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version
Chinese version, very easy to use

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
