Home >Backend Development >PHP Tutorial >PHP去除BOM头后出现乱码

PHP去除BOM头后出现乱码

WBOY
WBOYOriginal
2016-06-23 14:04:051002browse

程序用的是Notepad++文本编辑器编写的,当选择格式->以UTF-8格式编码后,中文字符(从数据库读取,存储到$_SESSION中)可以正常显示,但是会出现以下警告

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at E:\wamp\www\biyesheji\login_check.php:1) in E:\wamp\www\biyesheji\login_check.php on line 1

Warning: Cannot modify header information - headers already sent by (output started at E:\wamp\www\biyesheji\login_check.php:1) in E:\wamp\www\biyesheji\login_check.php 
Array ( [username] => 张三 [userid] => 2009011105 [role] => 3 ) 

登录成功!
5秒钟后进行跳转

去掉BOM头后,警告消失,但是中文字符全部变成乱码

Array ( [username] => 寮?? [userid] => 2009011105 [role] => 3 ) 
?诲????!
5绉?????琛?烦杞

求解决方法


回复讨论(解决方案)

header('Content-type: text/html; charset=utf-8');
加一句申明是UTF-8编码,不然浏览器可能会自己去检测

PHP code?1header('Content-type: text/html; charset=utf-8');加一句申明是UTF-8编码,不然浏览器可能会自己去检测
解决了,多谢

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