How to remove multiple UTF-8 BOM sequences
you would use the following code to remove utf8 bom
//Remove UTF8 Bomfunction remove_utf8_bom($text){ $bom = pack('H*','EFBBBF'); $text = preg_replace("/^$bom/", '', $text); return $text;}
try:
// -------- read the file-content ----$str = file_get_contents($source_file); // -------- remove the utf-8 BOM ----$str = str_replace("\xEF\xBB\xBF",'',$str); // -------- get the Object from JSON ---- $obj = json_decode($str);
:)
Another way to remove the BOM which is Unicode code point U+FEFF
$str = preg_replace('/\x{FEFF}/u', '', $file);