Created
April 7, 2010 09:54
-
-
Save donamkhanh/358712 to your computer and use it in GitHub Desktop.
json_encode returns null for certain strings. See: http://bugs.php.net/49588
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$a = "Hello, I'm an other charset éc éc"; | |
$b = htmlentities($a, ENT_QUOTES, 'UTF-8'); | |
$c = htmlentities($a); | |
echo "\n", json_encode($a); //ouput will be "Hello, I'm an other charset " | |
echo "\n", json_encode($b); //ouput will be "" (NULL) | |
echo "\n", json_encode($c); //ouput will be "Hello, I'm an other charset éc éc" |
Thanks for your comment. I thought I still can check the character encoding based on input (signed - but still under ACSII encoding) but forgot about the file encoding (when I test). And the "character set" of the DB too :(
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the file is encoded correctly
string(45) ""Hello, I'm an other charset \u00e9c \u00e9c""
string(54) ""Hello, I'm an other charset éc éc""
string(61) ""Hello, I'm an other charset éc éc""