Phper Use UTF-8 Precautions

Source: Internet
Author: User



The function 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 encoding, see: "PHP matches regular expressions for UTF-8 Chinese characters"
1, Editor: Do not use any Microsoft editor, what Frontpage,web Designer, Notepad, WordPad and so on, can be lost all lost, because these editors will be in your UTF-8 document before the BOM, the specific description of the BOM, you can find here, When I went directly to the notebook to UTF-8 cover the original file, resulting in a large number 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), you have to choose Utf8_general_ci finishing Format (collation), in PHP using mysql_connect () function to connect the data, you need to add a sentence:
mysql_query (' Set names "UTF8");

3, PHP:
Use the Mbstring 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:
CODE:

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
&lt;? Php
$str = "<a href= ' Test ' > Chinese </a>";
Echo htmlentities ($str, Ent_compat, "UTF-8"); Display (source code) <a href= ' Test ' > Juan?

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.