php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50950 json_encode null some special chars
Submitted: 2010-02-06 22:19 UTC Modified: 2010-02-06 22:39 UTC
From: schlapn at mail dot 3dl dot am Assigned:
Status: Not a bug Package: JSON related
PHP Version: 5.3.1 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: schlapn at mail dot 3dl dot am
New email:
PHP Version: OS:

 

 [2010-02-06 22:19 UTC] schlapn at mail dot 3dl dot am
Description:
------------
Hi, 

I got the following array and want to enode it to json format:

print_r($hier);

------
 ["ID"]=>  int(254) ["XYID"]=>  int(4) ["Inhalt"]=>  string(127) "@hallowas geht " ["Name"]=>  string(4) "falti" ["Datum"]=>  string(19) "2010-02-06 17:57:54" ["Gru?"]=>  string(14) "TOOTO|??|MOOTO" ["Affe"] => string (4) "Pans"
------  

but the result was 

print_r(json_encode($hier));
----
{"ID":254,"XYID":4,"Inhalt":"@hallowas geht ","Name":"falti","Datum":"2010-02-06 17:57:54","Gru?":null,"Affe":"Pans"}
---  

As you can see the string with the '?' char results a null in the encoded JSON. I uses the option Paramters (JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP) but nothing solved the problem, when I used other chars instead it worked properly.

I saw someone having this Problem on a Linux and MacOs Machine with PHP 5.3 but the bug is still there on Windows machines with PHP 5.3.1

Reproduce code:
---------------
print_r($hier);

------
 ["ID"]=>  int(254) ["XYID"]=>  int(4) ["Inhalt"]=>  string(127) "@hallowas geht " ["Name"]=>  string(4) "falti" ["Datum"]=>  string(19) "2010-02-06 17:57:54" ["Gru?"]=>  string(14) "TOOTO|??|MOOTO" ["Affe"] => string (4) "Pans"
------  
results:

print_r(json_encode($hier));
----
{"ID":254,"XYID":4,"Inhalt":"@hallowas geht ","Name":"falti","Datum":"2010-02-06 17:57:54","Gru?":null,"Affe":"Pans"}
---  

Expected result:
----------------
print_r($hier);

------
 ["ID"]=>  int(254) ["XYID"]=>  int(4) ["Inhalt"]=>  string(127) "@hallowas geht " ["Name"]=>  string(4) "falti" ["Datum"]=>  string(19) "2010-02-06 17:57:54" ["Gru?"]=>  string(14) "TOOTO|??|MOOTO" ["Affe"] => string (4) "Pans"
------  

but the result was 

print_r(json_encode($hier));
----
{"ID":254,"XYID":4,"Inhalt":"@hallowas geht ","Name":"falti","Datum":"2010-02-06 17:57:54","Gru?":"TOOTO|??|MOOTO","Affe":"Pans"}
---  

Actual result:
--------------
print_r(json_encode($hier));
----
{"ID":254,"XYID":4,"Inhalt":"@hallowas geht ","Name":"falti","Datum":"2010-02-06 17:57:54","Gru?":null,"Affe":"Pans"}
---  

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-06 22:39 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

you have to use utf-8 encoded input. Make sure your file is saved as utf-8orconvert the string.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC