phpjson

json_encode function: special characters


Elements of an array containing special characters are converted to empty strings when encoding the array with json_encode:

$arr = array ( "funds" => "ComStage STOXX®Europe 600 Techn NR ETF", "time"=>....);
$json = json_encode($arr);

After JSON encoding the element [funds] is null. It happens only with special characters (copyright, trademark etc) like the ones in "ComStage STOXX®Europe 600 Techn NR ETF".

Any suggestions?

Thanks


Solution

  • Your input has to be encoded as UTF-8 or ISO-8859-1.

    http://www.php.net/manual/en/function.json-encode.php

    Because if you try to convert an array of non-utf8 characters you'll be getting 0 as return value.


    Since 5.5.0 The return value on failure was changed from null string to FALSE.