Edit report at http://bugs.php.net/bug.php?id=49588&edit=1

 ID:                 49588
 Comment by:         gtrujillos at gmail dot com
 Reported by:        fernando at consultorpc dot com
 Summary:            json_encode returns null for certain strings
 Status:             Bogus
 Type:               Bug
 Package:            JSON related
 Operating System:   Linux/Mac OSX Leopard
 PHP Version:        5.3.0
 Block user comment: N
 Private report:     N

 New Comment:

A useful solution:



http://efreedom.com/Question/1-2790027/UTF-Character-Encoding-Battles-Json-Encode


Previous Comments:
------------------------------------------------------------------------
[2010-12-27 23:19:58] gtrujillos at gmail dot com

A use full solution:



http://efreedom.com/Question/1-2790027/UTF-Character-Encoding-Battles-Json-Encode

------------------------------------------------------------------------
[2010-04-07 13:21:58] pcdinh at gmail dot com

Hi arievanziel,



In your case, the character 'é' may be encoded in 'latin1'. If you save
the code in a UTF-8 encoded file you will find that the result will be 



é"é"



as expected

------------------------------------------------------------------------
[2010-04-01 15:13:57] arievanziel at gmail dot com

json_encode returns null for a string with é or (for example) ä in
it.



Reproduce code:



$test = "é";

echo $test;

echo json_encode($test);



A possible workaround could be to use (especially if you will use the 

json_encode string as html output):



$test = "é";

$test = htmlentities($test, UTF-8);

echo $test;

echo json_encode($test);

------------------------------------------------------------------------
[2009-09-18 13:29:20] scott...@php.net

It only appears of display_errors is on though with 5.3.1+ you can also
detect it by looking at json_last_error()

------------------------------------------------------------------------
[2009-09-18 12:54:42] j...@php.net

PHP Warning:  json_encode(): Invalid UTF-8 sequence in argument in
Command line code on line 1

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    http://bugs.php.net/bug.php?id=49588


-- 
Edit this bug report at http://bugs.php.net/bug.php?id=49588&edit=1

Reply via email to