Several PHP Chinese garbled questions are worth noting

Source: Internet
Author: User
Several PHP Chinese garbled characters are worth noting that Chinese garbled characters in PHP are one of the common problems in PHP development. Website construction: Chinese garbled characters in www. ucantech. comPHP sometimes occur on the webpage. Some are generated during MySQL interaction and sometimes related to the operating system. The following is a summary. I. First of all, the best and fastest solution for PHP webpage encoding is that the page declarative encoding is consistent with the internal encoding of the database. if the page numbers requested by the page are several PHP Chinese characters garbled, it is worth noting that
PHP Chinese garbled characters are one of the common problems in PHP development.
Website construction: http://www.ucantech.com/

PHP Chinese garbled characters sometimes occur on the web page, and some occur in the MySQL interaction process, sometimes related to the operating system. The following is a summary.

I. first, PHP webpage code

The best and fastest solution is that the encoding of the page declaration is consistent with the internal encoding of the database. if the requested page number is inconsistent with the internal encoding of the database, set the connection encoding, mysql_query ("set names kkk"); KKK is the connection encoding. it will certainly solve the garbled problem.

1. the PHP file encoding should match the webpage encoding. if you want to use gb2312 encoding, php needs to output the header ("Content-Type: text/html; charset = gb2312") and add it to the static page. The encoding format of all files is ANSI, which can be opened in Notepad. save it as ANSI and overwrite the source file. B. If you want to use UTF-8 encoding, php needs to output headers: header ("Content-Type: text/html; charset = utf-8") and add static pages The encoding format of all files is UTF-8. It may be a little troublesome to save it as UTF-8. generally, BOM is generated at the beginning of the UTF-8 file. If session is used, problems may occur. you can use editplus to save it in editplus, tool-> parameter selection-> File-> UTF-8 signature, select the total is to delete, and then save to remove the BOM information.

2. php itself is not Unicode. all functions such as substr must be changed to mb_substr (mbstring extension is required), or iconv transcoding is used. Fblww-0105)

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.