Home  >  Article  >  Backend Development  >  Ten steps to solve the problem of using UTF-8 encoding in PHP_PHP tutorial

Ten steps to solve the problem of using UTF-8 encoding in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:30:32845browse

I said before that if the JS file is not UTF8, there will be bugs in IE, so the JS code must also use UTF-8. Databases must also use UTF-8.
php(as the current mainstream development language)Using UTF-8 to summarize:

  1. php(as the current mainstream development language)The file itself must be UTF-8 encoded. Unlike Java, which generates class files, this avoids this problem.
  2. php(as the current mainstream development language)To output the header: header("Content-Type: text/html; charset=UTF-8")
  3. The meta tag doesn’t matter, all browsers that have a header will parse it according to the header.
  4. All peripherals must use UTF8, including databases, *.js, *.css (CSS has little impact)
  5. php (as the current mainstream development language) itself is not Unicode. All functions such as substr must be changed to mb_substr (need to install the mbstring extension); or use iconv to transcode (basically Linux has been installed, if not, download, tar, make, make install, very simple)
  6. my.ini:
    [MySQL(The best combination with PHP)]
    default-character-set=utf8
    [MySQL(With PHP) The best combination)d]
    default-character-set=utf8
    default-storage-engine=MyISAM
    in [MySQL(The best combination with PHP)d] add:
    default-collation=utf8_bin
    init_connect=SET NAMES utf8
  7. Add mb_internal_encoding(utf-8) in front of the php (as the current mainstream development language)
    program that needs to perform database operations;
  8. Add ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin at the end of create table
  9. php(as the current mainstream development language)MyAdmin/config.inc.php(as the current mainstream development language)
    $cfg[DefaultCharset] = utf-8;
    $cfg[RecodingEngine] = iconv;
  10. php(as the current mainstream development language)When Admin exports data
    uncheck "Use hexadecimal display for binary areas"

Particularly frustrating: the file system function does not support UTF-8!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/509161.htmlTechArticleI have said before that if the JS file is not UTF8, there will be bugs in IE, so the JS code must also use UTF-8. Databases must also use UTF-8. php (as the current mainstream development language) is summarized in UTF-8: ph...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn