Bug #51947 [Com]: json_encode fails to decode non-breaking spaces
| From: | arpad dot borsos at googlemail dot com | Date: | Sat, 29 May 2010 07:46:28 +0000 |
| Subject: | Bug #51947 [Com]: json_encode fails to decode non-breaking spaces | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-150930@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=51947&edit=1
ID: 51947
Comment by: arpad dot borsos at googlemail dot com
Reported by: ehsan dot akhgari at gmail dot com
Summary: json_encode fails to decode non-breaking spaces
Status: Open
Type: Bug
Package: JSON related
Operating System: Windows, Linux
PHP Version: 5.3.2
New Comment:
I have an outdated 5.2.4 on my server which returns an empty string
instead of null in that case.
Anyway, 0xa0 (160) is not a valid utf8 character (it needs to be 0xc2
0xa0) and thus invalid json. I believe PHP is right about erroring out
in this case.
var_dump(json_encode(utf8_encode(chr(0xa0))));
and
$encutf8 = json_encode(chr(0xc2).chr(0xa0));
var_dump($encutf8);
both work fine.
Can you check the output of json_last_error() please?
Previous Comments:
------------------------------------------------------------------------
[2010-05-29 01:24:00] ehsan dot akhgari at gmail dot com
Description:
------------
I've seen that json_encode cannot encode a non-breaking space character,
and returns "null". I've reproduced this on php5.3.2 on Windows and
Linux.
Test script:
---------------
<?php
var_dump(json_encode(chr(160)));
?>
Expected result:
----------------
string(3) "" ""
Actual result:
--------------
string(4) "null"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51947&edit=1