Generally PHP files created by default is not Utf-8 format, the Web-based solution is as follows:

Source: Internet
Author: User

1. PHP itself is not encoded, and all strings are generally considered binary streams. So only the string you need to enter is Utf-8. If the string has other encodings, you can use the Iconv series function to convert the encoding.

2, note $content = Iconv ("Utf-8", "Gb2312//ignore", $content); IGNORE Ignore error

<?php$f=fopen("test.txt", "wb");$text=utf8_encode("a!"); //先用函数utf8_encode将所需写入的数据变成UTF编码格式。$text="\xEF\xBB\xBF".$text;//"\xEF\xBB\xBF",在没有utf8中文情况下,这串字符不可缺少,生成的文件将成为UTF-8格式,否则依然是ANSI格式。fputs($f, $text);//写入。fclose($f);?>

This creates the file encoding format is really utf-8, but placed in the file of Chinese characters appear garbled phenomenon, after some debugging, the code is as follows:

<?php$ctxtsubmit="好呀";$f=fopen("../".$file, "wb");    //$text=utf8_encode($ctxtsubmit);    //先用函数utf8_encode将所需写入的数据变成UTF编码格式。    $text="\xEF\xBB\xBF".$ctxtsubmit;     //"\xEF\xBB\xBF",在没有utf8中文情况下,这串字符不可缺少,生成的文件将成为UTF-8格式,否则依然是ANSI格式。    fputs($f, $text);    //写入。     fclose($f); ?>

As for "\XEF\XBB\XBF" Why add this string, I do not understand

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.