Home  >  Article  >  Backend Development  >  PHP queries the database and outputs garbled characters

PHP queries the database and outputs garbled characters

王林
王林Original
2019-10-12 11:46:413524browse

PHP queries the database and outputs garbled characters

PHP query database output garbled code

1. First, you must figure out the sorting rules (encoding) of your database, tables, and fields. Method)

2. Use

$charset=mysqli_character_set_name($con);  //返回数据库默认字符集的编码utf8
echo "默认字符集为: " . $charset;

in php. 3. The encoding rules of the php header should be consistent with the database

header("Content-type:text/html;charset=utf8");//字符编码设置

4. The coding rules of the html page must also be consistent

<meta http-equiv="Content-Type" content="text/html; charset=utf8">

Recommended tutorial: PHP video tutorial

The above is the detailed content of PHP queries the database and outputs garbled characters. 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