PHPer use UTF-8 considerations-PHP source code

Source: Internet
Author: User
Ec (2); the role of this article is to avoid the use of UTF-8 encoding and the problem of garbled, does not contain the specific garbled solution and the content of encoding conversion. For a deep understanding of UTF-8 encoding, see: PHP match UTF-8 Chinese Character Regular Expression 1, Editor: Do not use any Microsoft Editor, what front page, WebDesigner, notepad, wordpad or something, can be lost all open, because these editors will generate the script ec (2) Before your UTF-8 document; script




The function of this paper is to avoid the garbled problem caused by the use of UTF-8 encoding in an all-round way, does not contain the specific garbled solution and the content of encoding conversion. For more information about UTF-8 encoding, see PHP Regular Expressions matching Chinese Characters in UTF-8
1. Editor: Do not use any Microsoft Editor, what front page, Web Designer, notepad, WordPad or something, can be lost all open, because these editors will generate BOM in front of your UTF-8 document, BOM specific instructions, can be found here, when I directly take notepad to cover the original file, resulting in a large number of code damage, the memory is still new.
2. MySQL database: when creating databases, creating tables, and creating fields (note that there are three fields), You must select utf8_general_ci sorting format (Collation) and use mysql_connect () in PHP () after the function connects data, you need to add the following sentence:
Mysql_query (''set names "utf8 "'');

3. PHP:
Use the mbstring library instead of the iconv library.
Use preg instead of ereg to process characters.
When using the htmlentities () function, the html_entity_decode () function must contain the third parameter:
CODE:


<? Php
$ Str = "Chinese ";
Echo htmlentities ($ str, ENT_COMPAT, "UTF-8"); // display (inside the source code) 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.