php乱码

1:php 编码是utf-8 但是接口需要是gbk 这么办??

$message = "你的微点管理地址为:".$shortUrl." [请保存信息]";
//echo $message."<br>";exit;
$message=iconv("UTF-8","gb2312",$message);

2:接口返回时gbk 但是php页面时utf8?

$result=file_get_contents($jiekouurl);
$html = iconv("gbk", "utf-8",$result);

$doc = new DOMDocument();
$xml=simplexml_load_string($html);

$humans = $doc->getElementsByTagName("result");

3:html body上面有空白 ?

用editplus 去掉+bom

4:电脑上面显示正常,但是手机上乱码 ?

用editplus 去掉+bom

特别是手机上面 有些地方如果需要gkb或者utf8转码的时候 ,第一步先去掉+bom

5:php alert输出乱码

header("Content-Type:text/html;charset=utf-8");
echo '<script>alert("创建网店失败,你已经复制过这店");window.location.href="/Weidian/show/token/'.$token.'"</script>';

 6:ajax乱码

jQuery(form).ajaxSubmit({ 
url: "ajax.aspx?a=memberlogin", 
type: "post", 
dataType: "json", 
contentType: "application/x-www-form-urlencoded; charset=utf-8", 
success: showLoginResponse 
}); 

如果还不行 主要是你的php文件有问题,你重新新建一个php文件,编码为utf8

原文地址:https://www.cnblogs.com/hxl2009/p/3598742.html