If you know the data is in UTF8 than you want to set up the header.

I wrote a solution answering to another tread.

The solution is the following: As the UTF-8 byte-order mark is \xef\xbb\xbf we should add it to the document's header.

<?php
function writeStringToFile($file, $string){
$f=fopen($file,"wb");
$file="\xEF\xBB\xBF".$file;// this is what makes the magic
fputs($f, $string);
fclose($f);}?>

You can adapt it to your code, basically you just want to make sure that you write a UTF8 file (as you said you know your content is UTF8 encoded).

answered Aug 31 '12 at 12:04

 
   
UTF8 BOM meaning 0xEF,0xBB,0xBF, which is
precisely what I suggested.

Now you obviously can create a file as UTF-8 by changing settings in
your IDE. But the same thing can be achieved using just PHP.
– 
Florin Sima
Sep 10 '12 at 15:30

   
+1 This should be the correct answer
– 
Ergec
Aug 14 '13 at 18:38

最新文章

  1. 用SQL Server(T-SQL)获取连接字符串
  2. js计算字符串出现个数
  3. 通过创建临时表合并hive小文件
  4. valueOf()方法
  5. 20135231 —— Linux 基础入门学习
  6. Coding the Matrix (3):矩阵
  7. Bluetooth GATT介绍
  8. const char *p、char const *p、char * const p的区别?
  9. javascript事件学习笔记
  10. uva 11069
  11. 基于Equinox构建OSGi项目
  12. (*p)++ 与 *p++ 与 ++*p 拨开一团迷雾
  13. javascript深入之location对象和history对象
  14. Java的Exception和Error面试题10问10答
  15. c语言int型和char型的自动类型转换
  16. 网络流 最大流—最小割 之SAP算法 详解
  17. FFmpeg中subtitle demuxer实现
  18. Scala 闭包
  19. linux 获取shell内置命令帮助信息 help xx
  20. Intellij Idea上Spring Boot编译报错:Error:(3, 32) java: 程序包org.springframework.boot不存在

热门文章

  1. hdoj3586 (树形dp)
  2. [CF261E]Maxim and Calculator_搜索_欧拉筛素数_动态规划
  3. vue中的axios.post使用json数据传输,出现请求头字段内容类型是不被允许的情况的解决方案
  4. go 计算 MD5
  5. DB2创建EMP和DEPT并进行基础操作
  6. Thinking In Java 4th Chap4 控制执行流程
  7. python — mysql基础知识
  8. Ubuntu18.04安装MySQL与默认编码设置
  9. 0502 xss 实验
  10. 修改一张MyISAM表row_format为fixed为InnoDB表报错处理