Home  >  Article  >  Backend Development  >  How to set character set encoding in php?

How to set character set encoding in php?

青灯夜游
青灯夜游Original
2020-11-04 10:46:092659browse

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.

How to set character set encoding in php?

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(&#39;Content-type:text/html;charset=utf-8&#39;);
?>

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(&#39;Location: http://www.example.com/&#39;);
?>

Grammar

header(string,replace,http_response_code)

How to set character set encoding in php?

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!

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