dtcuv8044 2019-06-14 13:55
浏览 1516
已采纳

如何回显curl命令中使用的url /如何使返回的中文字符可读?

  1. How could I echo the url that I use to curl data from along with the data showed?

  2. My server does not display the Chinese characters properly from this curl, How can I fix it?

function mobile_number(){

        $tel = isset($_GET['tel'])?$_GET['tel']:’';

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, 'https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=' . $tel);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $resp = curl_exec($curl);


        print_r($resp); 
    }

This the result I get back:

__GetZoneResult_ = { mts:'1357465', province:'����', catName:'�й��ƶ�', telString:'13574652375', areaVid:'30514', ispVid:'3236139', carrier:'�����ƶ�’ }
  • 写回答

1条回答 默认 最新

  • duanjia4817 2019-06-14 15:54
    关注

    it's a problem with whatever you're using to view the results.

    for example, if you're using a web browser to view the results, then the problem is that you're not telling the web browser to interpret it as unicode, and your browser try to interpret it as ASCII or something, in which case the fix is to add

    header("Content-Type: text/plain;charset=utf-8"); at the top of your script.

    if you're using a terminal.. idk, maybe try using a better terminal? bash maybe?

    PS, you're vulnerable to variable injection and variable corruption on line 6 (for example the number +47123123 would be converted to 47123123, the + would be lost!) the code should be

    curl_setopt($curl, CURLOPT_URL, 'https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=' . urlencode($tel));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证