Home > Backend Development > PHP Tutorial > php生成utf8格式编码的文件

php生成utf8格式编码的文件

WBOY
Release: 2016-06-20 13:04:39
Original
1283 people have browsed it

在线生成带有汉字字符的文件时,为了程序运行中出现乱码,我们需要把在线生成的文件保存为utf8格式,以便程序不乱码,大家都知道,PHP可以直接创建文件保存的格式都是ANSI,无法保存UTF8格式,经过上网查询,和自己实践,研究结果如下:以下代码可以直接创建urt8格式的文本文件: 

<p><?php   $ctxtsubmit="PHP建站门户www.scutephp.com";   </p><p>$f=fopen("../".$file, "wb");  </p><p> $text=utf8_encode($ctxtsubmit);   //先用函数utf8_encode将所需写入的数据变成UTF编码格式。  $text="\xEF\xBB\xBF".$ctxtsubmit;    //"\xEF\xBB\xBF",这串字符不可缺少,生成的文件将成为UTF-8格式,否则依然是ANSI格式。  </p><p> fputs($f, $text);   fclose($f);   </p><p> ?></p>
Copy after login


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