note 113505 added to function.json-decode

From: Date: Mon, 21 Oct 2013 10:43:58 +0000
Subject: note 113505 added to function.json-decode
Groups: php.notes 
Request: Send a blank email to php-notes+get-196598@lists.php.net to get a copy of this message
As Christian mentioned below, you can strip the leading BOM (byte order mark) if your result is not being parsed properly. I had a web service I had written that was returning utf8 encoded json, but json_decode() would not parse it. Nothing else seemed to work for me until I tried this. Here is an example function to do so (taken from http://stackoverflow.com/questions/10290849/how-to-remove-multiple-utf-8-bom-sequences-before-doctype): <?php //Remove UTF8 Bom function remove_utf8_bom($text) { $bom = pack('H*','EFBBBF'); $text = preg_replace("/^$bom/", '', $text); return $text; } ?> Good luck! Hope this helps! ---- Server IP: 69.147.83.199 Probable Submitter: 75.139.146.118 ---- Manual Page -- http://php.net/manual/en/function.json-decode.php Edit -- https://master.php.net/note/edit/113505 Del: integrated -- https://master.php.net/note/delete/113505/integrated Del: useless -- https://master.php.net/note/delete/113505/useless Del: bad code -- https://master.php.net/note/delete/113505/bad+code Del: spam -- https://master.php.net/note/delete/113505/spam Del: non-english -- https://master.php.net/note/delete/113505/non-english Del: in docs -- https://master.php.net/note/delete/113505/in+docs Del: other reasons-- https://master.php.net/note/delete/113505 Reject -- https://master.php.net/note/reject/113505 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#196598) next »