为什么在第二次调用时,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 ?

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

In situations like this, if I can get one element to work, I wrap that working element in a function or a class for reuse as is. See if this is what you are looking for:

function cURL($url = false,$settings = false)
    {
        $string =   (!empty($settings['toString']));
        $json   =   (!empty($settings['toJson']));

        $ch     =   curl_init();
        curl_setopt($ch,CURLOPT_URL,'http://huger.blog.ir/rss/');
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
        $response   =   curl_exec($ch);

        if($string)
            $response   =   (string) $response;
        elseif($json)
            $response   =   json_decode($response,true);

        curl_close($ch);
        return $response;
    }

function toLink($cURL = false)
    {
        $l      =   strpos($cURL,'</link>');
        $start  =   strpos($cURL,'<link>',$l);
        $end    =   strpos($cURL,'</link>',$l+2);
        $link   =   substr($cURL, $start , $end-$start);
        // As noted by @Hari Swaminathan, you have a <link> at the front,
        // so strip_tags will remove that
        return strip_tags($link);
    }

$link   =   cURL('http://huger.blog.ir/rss/',array("toString"=>true));

echo cURL(toLink($link));