请问这个utf-8简单的页面,如何从数据库里取的数据中文都是问号,试的办法都不行

WBOY
Release: 2016-06-13 10:13:08
Original
795 people have browsed it

请教这个utf-8简单的页面,怎么从数据库里取的数据中文都是问号,试的办法都不行

HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>中文乱码</title><?php $MySQLConnection = mysql_connect( "localhost", "root", "123456" );@mysql_select_db( "first");$result = mysql_query("SELECT * FROM `biao`");?><div>表格1</div>
Copy after login
=$row['hao']; ?> =$row['mingzi'] ?>


现在div中的“表格1”可以正常显示,就是从数据库提取的数据中文变问号,英文也正常

------解决方案--------------------
1.数据库取数据前 query("SET NAMES 'UTF8'"),注意数据库的相关编码也需要设置为UTF8
2.文件编码为utf-8格式 注意是文件编码
3.在php添加

header('Content-Type: text/html; charset=UTF-8'); 

Over.简称三码一致...
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!