Home >Backend Development >PHP Problem >What to do if php Chinese code is garbled
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.
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('127.0.0.1', 'root', '123456', 'test'); 本地地址 数据库登录名 登录密码 数据库名 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!