PHP去除BOM头的方法

BOM头是UTF-8来告诉编辑器:我是UTF8编码。它的编码是\xEF\xBB\xBF

但是PHP在设计之初并没有考虑到BOM头的问题,所以在编解码的时候很容易出现问题
    
$result = trim($result, "\xEF\xBB\xBF");
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;

 

posted @ 2016-08-18 18:16  侠岚之弋痕夕  阅读(295)  评论(0编辑  收藏  举报
Where is the starting point, we don't have a choice, but the destination where we can pursue!