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

fwrite() and UTF8 转载的更多相关文章

  1. 字符编码笔记:ASCII,Unicode和UTF-8(转载)

    作者: 阮一峰 日期: 2007年10月28日 今天中午,我突然想搞清楚Unicode和UTF-8之间的关系,于是就开始在网上查资料. 结果,这个问题比我想象的复杂,从午饭后一直看到晚上9点,才算初步 ...

  2. mysql 5.5 编码设置为utf8 转载自:http://outofcontrol.ca/thoughts/comments/change-mysql-5.5-default-character-set-to-utf8

    Change MySQL 5.5 default character-set to UTF8 连接里是linux下的 在window下my.ini Add under [client]  the fo ...

  3. CMD命令之 :修改windows的CMD窗口输出编码格式为UTF-8

    修改windows的CMD窗口输出编码格式为UTF-8 转载自 http://xuliduo.iteye.com/blog/639923 dos命令: chcp 65001  就是换成UTF-8代码页 ...

  4. ajax乱码问题 服务端 客户端 两种的解决方案--转载

    今天弄了一天的Ajax中文乱码问题,Ajax的乱码问题分为两种: 1. JavaScript输出的中文乱码, 比如:alert("中文乱码测试"); 2. 这第二种就是Ajax从服 ...

  5. json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1

    问题描述:使用Python代码将txt城市列表文件转换为xls文件,源码如下, #!/usr/bin/env Python # coding=utf-8 import os import json i ...

  6. Sublime Text通过插件编译Sass为CSS及中文编译异常解决

    虽然PostCSS才是未来,但是Sass成熟稳定,拥有一大波忠实的使用者,及开源项目,且最近Bootstrap 4 alpha也从Less转到Sass了.所以了解Sass还是非常有必要的. 基于快速开 ...

  7. PHP+JQUEY+AJAX实现分页【转】

    HTML CSS #list{width:680px; height:530px; margin:2px auto; position:relative} #list ul li{float:left ...

  8. Navicat Premium下sql导入中文乱码解决方案

    今天帮忙朋友找bug的时候,准备导入她数据库里面的数据,所以我就试图在mysql管理工具Navicat下面导入相应的mysql命令.结果发现导入的中文字符全部变成乱码,所以做了如下这种尝试: 在“连接 ...

  9. 《Pandoc用户指南》之一

    @(编程) 1. 描述 Pandoc是一个用于从一种标记格式转换为另一种的Haskell库,还是一个使用该库的命令行工具.它可以读取markdown格式和Textile格式(的子集).reStruct ...

随机推荐

  1. Python Requests库 form-data 上传文件操作

    请求数据示例: ------WebKitFormBoundaryKLoWgrA4O40MayHM Content-Disposition: form-data; name="id" ...

  2. Unsupported major.minor version 52.0——解决

    Unsupported major.minor version 52.0 就是编辑用的是jdk8 而运行用的是jdk7, 改成jdk8就好了 参考文章:https://blog.csdn.net/qq ...

  3. Spring mybatis源码篇章-Mybatis主文件加载

    通过阅读源码对实现机制进行了解有利于陶冶情操,承接前文Spring mybatis源码篇章-SqlSessionFactory 前话 本文承接前文的内容继续往下扩展,通过Spring与Mybatis的 ...

  4. Design Excel Sum Formula

    Your task is to design the basic function of Excel and implement the function of sum formula. Specif ...

  5. 【转载】CASE WHEN 及 SELECT CASE WHEN的用法

    原文链接:https://www.cnblogs.com/aipan/p/7770611.html Case具有两种格式.简单Case函数和Case搜索函数. 简单Case函数 CASE sex WH ...

  6. php gd实现简单图片验证码与图片背景文字水印

    1.让水印文字铺满图片: 大致效果: 代码: <?php function appendSpreadTextMark($imageDir, $markText) { $fontFile = &q ...

  7. npm—入门指导

    npm npm是什么? NPM(node package manager),通常称为node包管理器.顾名思义,它的主要功能就是管理node包,包括:安装.卸载.更新.查看.搜索.发布等. npm的背 ...

  8. Linux与Windows的设备驱动模型对比

    Linux与Windows的设备驱动模型对比 名词缩写: API 应用程序接口(Application Program Interface ) ABI 应用系统二进制接口(Application Bi ...

  9. SpringBoot整合Redis---Jedis版

    目录 介绍 开发环境 pom文件引入 创建redis.properties配置文件 创建RedisConfig配置类 创建RedisUtil工具类 使用 效果 介绍 Redis简介 Redis 是完全 ...

  10. CN丶Moti-个人博客

    欢迎访问我的个人博客,获取更多有用的东西 链接一 链接二 也可以关注我的微信订阅号:CN丶Moti