douping4436 2015-11-19 07:10
浏览 115
已采纳

为什么在第二次调用时,php“curl”功能无法正常工作?

I am using php Curl for first time This is my code :

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'http://huger.blog.ir/rss/');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$full = curl_exec($ch);
curl_close($ch);
$full = (string)$full;
$l = strpos($full,'</link>');
$start = strpos($full,'<link>',$l);
$end = strpos($full,'</link>',$l+2);
global $link;
$link = substr($full, $start , $end-$start);
$v = curl_init();
curl_setopt($v,CURLOPT_URL,$link);
curl_setopt($v,CURLOPT_RETURNTRANSFER,true);
$page = curl_exec($v);
curl_close($v);
echo $page;

$ch curl does its job and $link made correctly. now i think my second curl ($v) doesnt work. can anyone help please ?

  • 写回答

2条回答 默认 最新

  • doushi7314 2015-11-19 07:50
    关注

    Try this code

    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,'http://huger.blog.ir/rss/');
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    $full = curl_exec($ch);
    curl_close($ch);
    $full = (string)$full;
    $l = strpos($full,'</link>');
    $start = strpos($full,'<link>',$l);
    $end = strpos($full,'</link>',$l+2);
    global $link;
    $link = substr($full, $start , $end-$start);
    var_dump($link);
    $v = curl_init();
    curl_setopt($v,CURLOPT_URL,$link);
    curl_setopt($v,CURLOPT_RETURNTRANSFER,true);
    $page = curl_exec($v);
    echo curl_error($v);
    curl_close($v);
    var_dump($page);
    

    You can see that there a tag in front of your url like

    string '<link>http://huger.blog.ir/1394/08/24/start' (length=43)
    

    This is causing the issue

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 android报错 brut.common.BrutException: could not exec (exit code = 1)
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!