PHP page encoding

Source: Internet
Author: User
Unified page Encoding

MySQL database encoding, HTML page encoding, PHP or HTML files themselves are encoded to be identical.
1, MySQL database encoding: When the database is set up to specify the encoding (such as GBK_CHINESE_CI), set up a data table, create a field, insert data, do not specify the encoding, will automatically inherit the database encoding.
When the database is connected, there is also code that can be executed after the database is connected
mysql_query (' SET NAMES gbk ');//convert GBK to your code, such as UTF8.
2, the HTML page encoding, refers to the setting of this line:

3, PHP or HTML file itself encoding: 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, also note that the data passed in JavaScript or flash is UTF-8 encoded, if the database and page encoding is GBK, to transcode, and then write to the database.
Iconv (' utf-8′, ' GBK ', $content);
5, in the PHP program, you can add a line to specify the code of the PHP source program:
Header (' content-type:text/html; CHARSET=GBK ');

PHP page encoding

1. Set the encoding in the file header
@header (' content-type:text/html;charset=utf-8′);
?
2. No use of the header, so the settings do not know and what is the difference, with the browser view what is the relationship??? [/quote]
They are all telling the browser what code to display the page, to say what is different, one is to send the original HTTP header, do not leave anything in the page, and you say this is written in the Web page.
First, if you don't have this in your Web page, sending an 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.
3
This function determines whether a string is a Chinese character
function Chkgb ($STR) {
if (Preg_match ("/^[". Chr (0XA1). " -". Chr (0xff)." +$/", $str)) {
return true;
} else {
return false;
}
}
if (CHKGB (')) {
echo ' Hello ';
}else{
echo "Bad";
//}
function tep_limit_string ($str _show, $length, $post _string= ' ... ') {
$mn _curr=0;
$str _output= ";
$str _show=trim ($str _show);
for ($i =0; $i<>
$str _tmp=substr ($str _show, $i, 1);
echo [...]

Article Link: http://www.cnblogs.com/eshow/archive/2011/10/05/2199305.html

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