問題描述
對(duì)于UTF-8無BOM格式的文件奸远,使用file_get_contents()
獲取其內(nèi)容之后,使用json_decode()
轉(zhuǎn)換為數(shù)組時(shí)完沪,結(jié)果將會(huì)為null。
解決方法
將BOM信息給去除
$text = file_get_contents('index.json');
$bom = pack('H*','EFBBBF');
$text = preg_replace("/^$bom/", '', $text);