Home  >  Article  >  Backend Development  >  What to do if php reads garbled data

What to do if php reads garbled data

藏色散人
藏色散人Original
2020-11-10 09:45:322696browse

Solution to garbled data read by php: First set the php webpage encoding to "UTF-8"; then connect to the database and insert the code as "$program_char="utf8";mysqli_set_charset( $con , $program_char );"; that's it.

What to do if php reads garbled data

Recommendation: "PHP Video Tutorial"

php obtains garbled data from the mysql database (already Solved)

Problem:

The database is in Chinese, and by searching the database on the web page, it is displayed as follows:

img/??.png

The data in the database is:

img/my.png

Solution:

First of all, if your php web page is UTF-8

<?php header("Content-Type:text/html;charset=UTF-8"); ?>

Connect to the database Then insert the following code:

$program_char = "utf8" ;
mysqli_set_charset( $con , $program_char );

If you use other formats, it is the same, just change $program_char

At this point: the web page can finally display the Chinese characters in the database, which has been bothering me for a day .

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