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.
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 "
id | name | countrycode | district | population | "; echo "
{$row['ID']} | {$row['Name']} | {$row['CountryCode']} | {$row['District']} | {$row['Population']} | "; echo "
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!