How to set character set in php

青灯夜游
Release: 2023-03-13 08:12:01
Original
4552 people have browsed it

In PHP, you can use the header() function to set the character set. You only need to add the "header('Content-type:text/html;charset=Character encoding');" code to the head of the PHP file. That’s it.

How to set character set in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

If our php file is displayed in the browser There is a problem with the character encoding, such as garbled characters.

At this time, we need to use the header() function to manually set the character set. The function of this function is to set the content of the response message, and the content-type field needs to be set in the response message.

content-type is used to define the type of network file and the encoding of the web page, and determines the format and encoding in which the file recipient will read the file.

Just insert the following line of code into the PHP file.

header("Content-Type:text/html;charset=字符编码");
Copy after login

If you want to set utf-8 encoding and let the browser process the page according to utf-8 encoding, you can:

header("Content-Type:text/html;charset=utf-8");
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to set character set in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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