Question

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.

No correct solution

OTHER TIPS

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

The \u00f1 part is fine: it refers to Unicode codepoint 00F1: "small letter n with tilde."

Something decoding that JSON will understand that to mean the same thing as ñ.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top