dongtao9887 2013-11-19 01:59
浏览 511

URL中的cURL和特殊字符

I am using curl_setopt($ch, CURLOPT_URL, $link) for fetching an external site, but there are special characters (&, ?, ;) in some urls and curl not work.

i used urldecode but still no luck, also replaced special characters with encoded ones (for example, %26 instead of &), but source site only returns a 404 page.

  • 写回答

2条回答 默认 最新

  • dtu72460 2013-11-19 02:38
    关注

    http://www.php.net/manual/en/function.curl-escape.php

    // Create a curl handle $ch = curl_init();

    // Escape a string used as a GET parameter $location = curl_escape($ch, 'Hofbräuhaus / München'); // Result: Hofbr%C3%A4uhaus%20%2F%20M%C3%BCnchen

    // Compose an URL with the escaped string $url = "http://example.com/add_location.php?location={$location}"; // Result: http://example.com/add_location.php?location=Hofbr%C3%A4uhaus%20%2F%20M%C3%BCnchen

    // Send HTTP request and close the handle curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_exec($ch); curl_close($ch);

    评论

报告相同问题?

悬赏问题

  • ¥20 simulink单相桥式整流电路
  • ¥35 问问51单片机流水灯的代码该怎么写
  • ¥15 关于#百度#的问题:感觉已经将字体段落、字体、页边距、纸张大小、文档网络调成与论文模板一致,为什么黄色部分字体左右的间距还是不一样啊,求私信发文件接收看一下
  • ¥15 stata webuse报错
  • ¥15 TypeError: Cannot read properties of undefined (reading 'status')
  • ¥15 如何利用AI去除图片中的竹架子
  • ¥15 python 写个基金爬取的代码,自动卖出功能
  • ¥15 Linux系统启动不起来
  • ¥15 为什么运行仿真数码管不亮(语言-c语言)
  • ¥15 陈仁良《直升机飞行动力学》小扰动线化方程如何推导