Reputation: 4254
I have following array in php
$array = array(
array('name'=>'abc', 'text'=>'اسلسصثصض صثصهخه عه☆anton & budi☆' ),
array('name'=>'xyz', 'text'=>'nice' ),
);
when i use json_encode, the result is different :
[
{
"name": "abc",
"text": "\u0627\u0633\u0644\u0633\u0635\u062b\u0635\u0636 \u0635\u062b\u0635\u0647\u062e\u0647 \u0639\u0647\u2606anton '<&>' budi\u2606"
},
{
"name": "xyz",
"text": "nice"
}
]
why the result is not like this ?
[
{
"name": "abc",
"text": "اسلسصثصض صثصهخه عه☆anton & budi☆"
},
{
"name": "xyz",
"text": "nice"
}
]
Thanks
Upvotes: 0
Views: 693
Reputation: 100175
Try this:
//for encode json_encode(array_map('base64_encode', $array)); //and for decode array_map('base64_decode', json_decode($array));
Hope it helps
Upvotes: 0
Reputation: 8101
Because it is encoded to JSON. With your first output, you are absolutely 100% certain that the browser will receive what you want it to. With the second, you cannot be sure.
Upvotes: 1
Reputation: 798526
Because PHP doesn't assume/allow a non-ASCII character set when encoding. Both results are equivalent when decoded.
Upvotes: 1