PHP Unified page encoding to avoid garbled problems, PHP page encoding garbled _php tutorial

Source: Internet
Author: User

PHP Unified page encoding to avoid garbled problems, PHP page encoding garbled


Unified page Encoding

MySQL database encoding, HTML page encoding, PHP or HTML files themselves are encoded to be identical.

1. MySQL Database code:
When you create a database, specify the encoding (such as GBK_CHINESE_CI), create a data table, create a field, insert data without specifying the encoding, and automatically inherit the database encoding.
When the database is connected, there is also code that can execute mysql_query (' SET NAMES GBK ') after the database is connected, and/or replace GBK with your code, such as UTF8.

2, the HTML page encoding, refers to the setting of this line:
Copy the Code code as follows:

3, the Code of PHP or HTML file itself:
With EditPlus open PHP file or HTML file, save, select the encoding, if the database and page encoding is GBK, then the code here choose ANSI; If the database and page encoding is Utf-8, then Utf-8 is also selected here.

4. The data passed in JavaScript or Flash is UTF-8 encoded:

Also note that the data passed in JavaScript or flash is UTF-8 encoded, and if the database and page encoding is GBK, transcode and then write to the database.
Copy the Code code as follows:
Iconv (' Utf-8 ', ' GBK ', $content);

5, in the PHP program, you can add a line to specify the code of the PHP source program:
Copy the Code code as follows:
Header (' content-type:text/html; CHARSET=GBK ');

PHP page encoding

1. Set the encoding in the file header
Copy the Code code as follows:
<?php
@header (' Content-type:text/html;charset=utf-8 ');
?>

The difference between 2.header and meta

With @header (' content-type:text/html; Charset=gbk ');
They are all telling the browser what code to display the page, to say what is different, the header is to send the original HTTP header, do not leave anything in the page, and Meta is written in the Web page.

First, if there is no meta in the Web page, then sending the HTTP header will work.

Second, sending the original HTTP header with the header () function can contain more content, and setting the encoding is just one of them.

Third, sometimes do not display what the page content, but to inform the browser with what code for follow-up action.

http://www.bkjia.com/PHPjc/981357.html www.bkjia.com true http://www.bkjia.com/PHPjc/981357.html techarticle PHP Unified page encoding to avoid garbled problems, PHP page encoding garbled page encoding unified MySQL database encoding, HTML page encoding, PHP or HTML files themselves encoded to be all the same. 1. MYSQ ...

  • 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.