In PHP, you can set the character set encoding through the header() function. The syntax format is "header('Content-type: text/html; charset=character encoding');". The character encoding can be set. For "utf-8", "GB2312", "GBK", etc.
Recommended: "PHP Video Tutorial"
php Set Character Set Encoding
If there is a problem with the character encoding displayed by your php file in the browser, you need to make some settings in the php file
<?php // 服务器读取的 编码设置 header('Content-type:text/html;charset=utf-8'); ?>
PHP header() function
## The #header() function sends raw HTTP headers to the client. It is important to realize that the header() function must be called before any actual output is sent (in PHP 4 and above, you can use output buffering to solve this problem):<html> <?php // This results in an error. // The output above is before the header() call header('Location: http://www.example.com/'); ?>
header(string,replace,http_response_code)
Extended information:
Characters (Character) are letters, numbers, and symbols in computers A general term for a character, a character can be a Chinese character, an English letter, an Arabic numeral, a punctuation mark, etc. Computers store data in binary form. The numbers, English, punctuation marks, Chinese characters and other characters we usually see on the display are the result of binary number conversion. Character set (Character set) defines the correspondence between characters and binary, and assigns unique numbers to characters. Common character sets include Unicode, ASCII, GBK, IOS-8859-1, etc. Character encoding (Character encoding) can also be called character set code, which specifies how to store character numbers in the computer. Most character sets only correspond to one character encoding, such as: ASCII, IOS-8859-1, GB2312, GBK, which all represent both the character set and the corresponding character encoding. So in general, the two can be considered synonyms. The exception is the Unicode character set, which has three encoding schemes, UTF-8, UTF-16, and UTF-32. The most commonly used encoding is UTF-8. For more programming-related knowledge, please visit:Introduction to Programming! !
The above is the detailed content of How to set character set encoding in php?. For more information, please follow other related articles on the PHP Chinese website!