I tried to get URL with curl. Return value contain unicode character. curl convert to \u for unicode character. How to get unicode character with curl ?
This is my code
<?php
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.ornagai.com/index.php/api/word/q/test/format/json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return=curl_exec($ch);
echo $return;
?>
Return json is following
[{"word":"test","state":"n","def":"\u1005\u102c\u1031\u1019\u1038\u1015\u1032\u103c\u104b \u1005\u1005\u1039\u1031\u1006\u1038\u103b\u1001\u1004\u1039\u1038\u104b \u1005\u1005\u1039\u1031\u1006\u1038\u1019\u1088\u104b \u1031\u1006\u1038\u1005\u1005\u1039\u103b\u1001\u1004\u1039\u1038\u104b \u1005\u1019\u1039\u1038\u101e\u1015\u1039\u103b\u1001\u1004\u1039\u1038\u104b"},{"word":"test","state":"v","def":"\u1005\u1005\u1039\r"},{"word":"test case","state":"n","def":"\u1031\u1014\u102c\u1004\u1039\u1039\u103b\u1016\u1010\u1039\u1011\u1036\u102f\u1038\u103b\u1016\u1005\u1039\u1019\u100a\u1039\u1037\u1005\u1036\u1014\u1019\u1030\u1014\u102c\u103b\u1015\u1021\u1019\u1088\u104b"},{"word":"test drive","state":"n","def":"\u1005\u1019\u1039\u1038\u101e\u1015\u1039\u1031\u1019\u102c\u1004\u1039\u1038\u108f\u103d\u1004\u1039\u103b\u1001\u1004\u1039\u1038\u104b \u1005\u1019\u1039\u1038\u101e\u1015\u1039\u1031\u1019\u102c\u1004\u1039\u1038\u101e\u100a\u1039\u104b"},{"word":"test match","state":"n","def":"\u1001\u101b\u1005\u1039\u1000\u1000\u1039\u104a\u101b\u1010\u1039\开发者_如何转开发u1062\u1018\u102e\u108f\u103d\u1005\u1039\u108f\u102d\u102f\u1004\u1039\u1004\u1036\u1021\u101e\u1004\u1039\u1038\u1019\u103a\u102c\u1038\u104f\u101c\u1000\u1039\u101b\u100a\u1039\u1005\u1019\u1039\u1038\u1015\u1032\u103c\u104b"},{"word":"test pilot","state":"n","def":"\u1031\u101c\u101a\u102c\u1009\u1039\u1015\u1036\u102f\u1005\u1036\u101e\u1005\u1039\u1000\u102d\u102f\u1005\u1019\u1039\u1038\u101e\u1015\u1039\u1031\u1019\u102c\u1004\u1039\u1038\u108f\u103d\u1004\u1039\u101e\u100a\u1039\u1037\u1031\u101c\u101a\u102c\u1009\u1039\u1019\u1089\u1038\u104b"},{"word":"test the waters","state":"idm","def":"\u1031\u101e\u103c\u1038\u1010\u102d\u102f\u1038\u1005\u1019\u1039\u1038\u101e\u100a\u1039\u104b"},{"word":"test-tube","state":"n","def":"\u1005\u1019\u1039\u1038\u101e\u1015\u1039\u1016\u1014\u1039\u103b\u1015\u103c\u1014\u1039\u104b \u1013\u102c\u1010\u1039\u1001\u1032\u103c\u1001\u1014\u1039\u1038\u1016\u1014\u1039\u103b\u1015\u103c\u1014\u1039\u104b"},{"word":"test-tube baby","state":"n","def":"\u1016\u1014\u1039\u103b\u1015\u103c\u1014\u1039\u101e\u1031\u108f\u1076\u101e\u102c\u1038\u104b"},{"word":"testable","state":"adj","def":"\u1005\u1019\u1039\u1038\u101e\u1015\u1039\u1005\u1005\u1039\u1031\u1006\u1038\u1001\u1036\u108f\u102d\u102f\u1004\u1039\u1031\u101e\u102c\u104b"}]
curl will get you whatever the remote server sends : it will not interpret anything, or do any modification on the data it gets.
If you have \uxxxx
characters in what curl returns, it's because those are returned by the remote server.
And having \uxxxx
characters in JSON data should not be a problem : it's the way unicode characters should be encoded, when using JSON -- see the definition of strings, on http://json.org/
Those should be interpreted correctly by Javascript, when using that JSON data.
精彩评论