Detailed explanation of common settings for PHP page encoding

WBOY
Release: 2016-07-25 09:12:19
Original
1322 people have browsed it

php's header() function is used to define the encoding of a php page (note: there cannot be any output in front, otherwise an error will be reported)

  1.  
Copy code

3. Encoding of PHP or html file itself: Use editplus to open the php file or html file. When saving, select the encoding. If the database and page encoding is gbk, select ansi as the encoding here; if the database and page encoding is utf-8, select utf-8 here as well.

4. The data passed in Javascript or Flash is encoded in utf-8. If the database and page encoding is gbk, it needs to be transcoded and then written to the database.

  1. iconv('utf-8', 'gbk', $content);
Copy code

5. In the PHP program, you can add a line to specify the encoding of the PHP source program: header('Content-type: text/html; charset=gbk');

4. The difference between upper and lower case of encoding characters (Only in mysql, other places recommend using uppercase UTF-8, GBK, GB2312) Only in MySQL can the alias "utf8" of "utf-8" be used, but in other places, always use uppercase "UTF-8". Specifically: always use uppercase "UTF-8" outside the command "mysql_query(set names utf8)".

The above introduces the various methods of setting page encoding in PHP, as well as the issues of database encoding, page encoding, and encoding character case in PHP. I hope it will be helpful to everyone.



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template