php loads html garbled code

王林
Release: 2023-02-25 10:40:01
Original
3156 people have browsed it

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" />
Copy after login

If it is html5:##

<meta charste="utf-8">
Copy after login

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");
?>
Copy after login

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");
Copy after login

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
Copy after login
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!

Related labels:
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
Popular Tutorials
More>
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!