|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43375 utf8_decode
Submitted: 2007-11-22 13:02 UTC Modified: 2008-09-08 10:32 UTC
Avg. Score:4.6 ± 0.7
Reproduced:6 of 6 (100.0%)
Same Version:3 (50.0%)
Same OS:2 (33.3%)
From: udo dot rader at bestsolution dot at Assigned:
Status: Not a bug Package: JSON related
PHP Version: 5.2.5 OS: Ubuntu
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: udo dot rader at bestsolution dot at
New email:
PHP Version: OS:


 [2007-11-22 13:02 UTC] udo dot rader at bestsolution dot at
I have some JSON data genereated by GWT that is sent to the PHP server end.

The JSON data recieved may contain special characters as well, that are regularly encoded as UTF8 (as required by the JSON specification). 

However, I find it impossible to access JSON data containing UTF8 encoded characters, because either utf8_decode or json_decode don't work as expected.

Reproduce code:
// this is how the JSON data is "normally" retrieved
//$JSONInput = file_get_contents( "php://input" );

$JSONInput = '{"foo":"\xc3\xb6\xc3\xb6"}';

$decodedJSONData = utf8_decode( $sampleJSONData );

echo "decoded JSON data: ".$decodedJSONData."<br>";

if ( $sampleJSONData == $decodedJSONData ) {
	echo "decoded is equal<br>";

if ( $sampleJSONData === $decodedJSONData ) {
	echo "decoded is binary equal<br>";

Expected result:
I expect utf8_decode to really decode the given data. In the example from above, it should decode the "\xc3\xb6" part to ? (&auml; in HTML)

Actual result:
nothing is decoded at all. 

However decoding takes place, if one replaces the double quotes with single quotes and vice versa in the $JSONInput string.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-08 10:32 UTC]
Properly encoded "auml" character in json should be "\u00c4" not "\xc3\xb6"
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Feb 21 03:01:33 2024 UTC