Example of creating a UTF-8 encoded file using phpfopen

Source: Internet
Author: User
If we use fopen directly to create will find that the file encoding is not a uft-8, then if you want to create a uft8 file we need some technical processing, below I searched some common methods on the network, let's take a look. use PHP to create the encoding format u... if we use fopen directly to create will find that the file encoding is not a uft-8, then if you want to create a uft8 file we need some technical processing, below I searched some common methods on the network, let's take a look.

Use PHP to create a UTF-8 file:

Step 1: Create a txt file, open, File-> save as xxx. php, and change the encoding to UTF-8, save.

Part 2: Add the following code to the PHP file:

 

Use this method to create the key points of the UTF-8 encoding file, ensure that the PHP code file encoding format is UTF-8, php code file encoding format is what is the file encoding created is what.

There are three main reasons to control the display of the page:

1. HTML code control: the head label in the standard HTML webpage file contains this code. In the code, charset = utf-8 tells the browser to display the content in the webpage in UTF-8 format.

2. PHP code control: if header ("content-Type: text/html; charset = utf-8") is added at the beginning of the PHP file, it is also used to tell the browser to display the content in the webpage in UTF-8 format. (Note: No echo-like output can be provided before this code)

3. file physical storage property control: open a file in notepad, and save the file as. what you see in "encoding" is the real encoding of the current file.

Add a fopen example with the following code:

  


The file encoding format created in this way is indeed UTF-8, but the Chinese characters in the file are garbled. after some debugging, the code is as follows:

   

I do not understand why this string is added to "\ xEF \ xBB \ xBF.

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.