How to solve the problem of php echo garbled characters

藏色散人
Release: 2023-03-07 11:06:01
Original
3171 people have browsed it
php echo is garbled because of encoding problems. The solution is to add a statement such as "header("Content-Type: text/html;charset=gb2312");" in front of php's echo.

How to solve the problem of php echo garbled characters

Recommended: "PHP Video Tutorial"

php echo Chinese garbled problem

The Chinese output by echo is displayed as garbled characters.

In fact, various server scripts should encounter this problem.

It is basically an encoding problem.

Generally speaking Considering encoding compatibility, most pages define the page character set as utf-8

. At this time, in order to display Chinese normally, you need to convert the encoding method, such as

echo iconv("GB2312"," UTF-8",'Chinese'); will not be garbled

There are other methods, such as

Add header("Content-Type: text/html; in front of php's echo charset=gb2312”);

Of course, the simplified Chinese page can also be simply,

Change the UTF-8 in to gb2312

At the same time, attach the PHP query database code Operation

城市信息一览表"; echo ""; echo ""; echo ""; echo ""; while($row=mysql_fetch_assoc($res)){ echo ""; echo ""; echo ""; } echo "
idnamecountrycodedistrictpopulation
{$row['ID']}{$row['Name']}{$row['CountryCode']}{$row['District']}{$row['Population']}
"; mysql_close($conn); ?>
Copy after login

How to solve the problem of php echo garbled characters

The above is the detailed content of How to solve the problem of php echo garbled characters. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!