douping4436 2015-11-18 23: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-18 23: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条)
编辑
预览

报告相同问题?