Bug #51947 [Opn->Bgs]: json_encode fails to decode non-breaking spaces
| From: | aharvey@php.net | Date: | Mon, 31 May 2010 03:08:01 +0000 |
| Subject: | Bug #51947 [Opn->Bgs]: json_encode fails to decode non-breaking spaces | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-150952@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
Updated by: aharvey@php.net
Reported by: ehsan dot akhgari at gmail dot com
Summary: json_encode fails to decode non-breaking spaces
-Status: Open
+Status: Bogus
Type: Bug
Package: JSON related
Operating System: Windows, Linux
PHP Version: 5.3.2
New Comment:
This is expected behaviour: as Arpad says, json_encode() expects input
to be encoded in UTF-8. json_encode(utf8_encode(chr(160))) behaves as
you'd expect: you get "\u00a0" as the result.
Previous Comments:
------------------------------------------------------------------------
[2010-05-29 09:46:28] arpad dot borsos at googlemail dot com
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?
------------------------------------------------------------------------
[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