Question by user1252306
I’m trying to encode an array which has special characters such as ñ. When I do that it returns null. I tried to use this option in Zend:
Zend_Json::$useBuiltinEncoderDecoder = true:
And it doesn’t return null but, for example, in this string “something with ñ” return “”something with u00f1”
And if a I use for json_encode, for example:
<? $string = "something with ñ"; echo "<pre>"; print_r($string); $encode_json = json_encode($string) ; print_r($encode_json); ?>
return is the same:
something with ñ
something with u00f1
And if I use utf8_enconde(), return this character u00c3 for ñ.
Some ideas to solve my problem? I need to save in the database at list words with ñ, if I can save another special character would be great.
Answer by Starx
You can encode Unicode Characters using json_encode() function as well
echo json_encode($yourdata, JSON_UNESCAPED_UNICODE);
Note: This is only available PHP 5.4 onwards