Home >Backend Development >PHP Problem >What to do if php Chinese code is garbled

What to do if php Chinese code is garbled

青灯夜游
青灯夜游Original
2021-03-10 11:00:311989browse

Solution: Use the header function to set the text encoding displayed on the page, for example "header("Content-Type:text/html;charset=utf-8");"; if you are linking to a database, you need to use mysqli_set_charset () sets the default client character set.

What to do if php Chinese code is garbled

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

Solution to Chinese garbled characters in PHP code The question

is in

<?php
header("Content-Type:text/html;charset=utf-8");   ////设置页面显示的文字编码,头部就写header函数处理成utf-8

//链接数据库
$con = mysqli_connect(&#39;127.0.0.1&#39;, &#39;root&#39;, &#39;123456&#39;, &#39;test&#39;); 本地地址 数据库登录名  登录密码  数据库名
mysqli_set_charset($con,"utf8");//设置默认客户端字符集。 数据库链接好后紧接着就设置字符集
?>

For more programming related knowledge, please visit: Programming Video! !

The above is the detailed content of What to do if php Chinese code is garbled. 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