to the header of the HTML, or add header("content-type:text/html;charset=utf-8" to the first line of the PHP script )."/> to the header of the HTML, or add header("content-type:text/html;charset=utf-8" to the first line of the PHP script ).">

Home >Backend Development >PHP Problem >php loads html garbled code

php loads html garbled code

王林
王林Original
2019-09-27 17:51:213233browse

php loads html garbled code

The interaction between PHP and html appears garbled

HTML part

If it is html, add in the head:
##

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

If it is html5:##

<meta charste="utf-8">

PHP part


If you are mixing it with HTML, it is recommended to add in the first line of the script:

<?php
header("content-type:text/html;charset=utf-8");
?>

After connecting to the database, set the encoding for the database (not permanently valid )

@$db = new mysqli($host, $user, $passwd)
$db->query("set names utf8");

If it is only for one or two parameters, you can use the iconv() function

$str = "测试"
$nes_str = iconv("gb2312", "UTF-8", $str)   // gbk转utf8
Recommended tutorial:

PHP video tutorial

The above is the detailed content of php loads html garbled code. 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