troubleshooting PHP mysql garbled problem _php tutorial

Source: Internet
Author: User
Tags php mysql
The purpose of this paper is to avoid the garbled problem caused by the use of UTF-8 encoding, which does not contain the specific garbled solution and the content of the code conversion. For an in-depth understanding of UTF-8 coding, refer to: "Regular expressions for text characters in PHP matching UTF-8"
1, Editor: Do not use any Microsoft editor, what Frontpage,web Designer, Notepad, WordPad and so on, can throw away all, because these editors will be in front of your UTF-8 document generated BOM, the specific description of the BOM, can be found here, That year I directly to the Notepad to UTF-8 overwrite the original file, causing a lot of code damage, still fresh memory.
2, MySQL database: Pay attention to build a library, build a table, build a field (note there are three places), should choose Utf8_general_ci Format (Collation), in PHP using the mysql_connect () function to connect the data, you need to add a sentence:
mysql_query (' Set names ' utf8 "');
3. PHP:
Use the MB library and do not use the Iconv library.
Use Preg instead of using Ereg to handle characters.
With the Htmlentities () function, the Html_entity_decode () function takes a third argument:

$str = "Chinese";
Echo htmlentities ($str, Ent_compat, "UTF-8"); Display (inside the source code) <a href= ' Test ' > Juan?

http://www.bkjia.com/PHPjc/632493.html www.bkjia.com true http://www.bkjia.com/PHPjc/632493.html techarticle The purpose of this paper is to avoid the garbled problem caused by the use of UTF-8 encoding, which does not contain the specific garbled solution and the content of the code conversion. In-depth knowledge of UTF-8 coding ...

  • Related Article

    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.