Does json support arabic characters?

I want to ask a quick question if json is supporting Arabic characters, which I mean when I look for something like the following

$values = $database->get_by_name('معاً'); echo json_encode(array('returnedFromValue' => $value."<br/>")); 

I am also looking for an Arabic result from a database, the return values ​​will be like

 {"returnedFromValue":"\u0627\u0644\u0645\u0639\u0627\u062f\u0649<br\/>"}{"returnedFromValue":"\u0627\u0644\u0645\u0639\u0627\u062f\u0649<br\/>"} 

What am I missing here? better to use XML in terms of support for arabic characters

+4
source share
3 answers

JSON , like XML, is some kind of data exchange format. he is not addicted to special encoding, so arabic characters should be good if you use an encoding that supports these characters (e.g. UFT-8 ).

+1
source

PHP 5.4.0 will support a special parameter for json_encode() called JSON_UNESCAPED_UNICODE . This stops the default behavior of converting characters to \uXXXX form.

 $value = 'معاً'; echo json_encode($value, JSON_UNESCAPED_UNICODE); // Outputs: "معاً" 
+2
source

These \u0627 -numbers are the Unicode codes for your Arabic letters. PHP uses them, not raw UTF-8 serialization, but they are. So yes, JSON really does support that. If the result string was printed on the client side (using Javascript), you will see the letters again.

0
source

All Articles