Home > Backend Development > PHP Tutorial > PHP fwrite 函数输出的文本编码为ANSI、小弟我需要UTF-8

PHP fwrite 函数输出的文本编码为ANSI、小弟我需要UTF-8

WBOY
Release: 2016-06-13 10:15:38
Original
1227 people have browsed it

PHP fwrite 函数输出的文本编码为ANSI、我需要UTF-8

$xmlContent = '假设这个字符串里是一段格式良好的XML文本信息、其中包括了特殊字符';

// 此处使用 mb_detect_encoding($xmlContent); 输出的结果是UTF-8

// 写入文件
$xmlFile = fopen("file.xml","w");
fwrite($xmlFile,$xmlContent);
fclose($xmlFile);


另、引用的全局配置文件有如此设置 header("Content-Type:text/html; charset=UTF-8");

用记事本打开file.xml文件、另存为、显示的是ANSI编码

我需要将file.xml保存为UTF-8、怎么改代码?

------解决方案--------------------
确实, 你的代码我测试过了。我这边没问题。。
你仔细检查下。php文件,echo mb_detect_encoding($xmlContent);是否为utf-8

Related labels:
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