PHP去除BOM头的方法

BOM头是UTF-8来告诉编辑器:我是UTF8编码。它的编码是xEFxBBxBF

但是PHP在设计之初并没有考虑到BOM头的问题,所以在编解码的时候很容易出现问题
    
$result = trim($result, "xEFxBBxBF");
print_r(json_decode($result, true));
exit;

 

还有一种比较矬:
1
2
3
4
5
    
$result = @iconv("UTF-8", "GBK//IGNORE", $result);
$result = @iconv("GBK", "UTF-8//IGNORE", $result);
 
print_r(json_decode($result, true));
exit;
原文地址:https://www.cnblogs.com/wuheng1991/p/5784963.html