在PHP中使用curl获取unicode字符

时间:2010-04-25 14:08:37

标签: php curl

我试图用curl获取网址。返回值包含unicode字符。 curl转换为\ u表示unicode。如何用curl获取unicode字符?

这是我的代码

<?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;
?>

返回json正在关注

[{"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"}]

1 个答案:

答案 0 :(得分:1)

curl将为您提供远程服务器发送的任何内容:它不会解释任何内容,也不会对其获取的数据进行任何修改。

如果curl返回时有\uxxxx个字符,那是因为远程服务器返回了这些字符。


在JSON数据中使用\uxxxx个字符应该不是问题:在使用JSON时,应该编码unicode字符的方式 - 请参阅http://json.org/上的字符串定义

使用该JSON数据时,Javascript应正确解释这些。