doulu1325 2010-04-25 14:08
浏览 123
已采纳

在PHP中使用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 ?

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"},{"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条回答 默认 最新

  • douzhi7754 2010-04-25 14:11
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧