在PHP中获取带curl的unicode字符 [英] Get unicode character with curl in PHP

查看:435
本文介绍了在PHP中获取带curl的unicode字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 ?

这是我的代码

<?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"}]


推荐答案

curl会得到远程服务器发送的任何东西:它不会解释任何东西,

curl will get you whatever the remote server sends : it will not interpret anything, or do any modification on the data it gets.

如果你在curl中返回了 \uxxxx 字符,远程服务器。

If you have \uxxxx characters in what curl returns, it's because those are returned by the remote server.



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


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/

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

Those should be interpreted correctly by Javascript, when using that JSON data.

这篇关于在PHP中获取带curl的unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆