2014-09-25 117 views
0

下面是我的代碼,但它沒有顯示輸出。現在我暫時將yahoo.com顯示爲curl輸出,但我的實際輸出url不同。任何人都可以告訴我代碼中有什麼問題?捲曲輸出不顯示

<?php 
    $myurl = "www.yahoo.com"; 
    curl_setopt ($ch, CURLOPT_URL, $myurl); 
    curl_setopt ($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $result= curl_exec ($ch); //execute and get the results 
    echo $result; //display the reuslt 
    curl_close($ch); 
?> 

回答

1

試試這個:

//Add $ch = curl_init(); 
$ch = curl_init(); 

$myurl = "www.yahoo.com"; 
curl_setopt ($ch, CURLOPT_URL, $myurl); 
curl_setopt ($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$result= curl_exec ($ch); //execute and get the results 
echo $result; //display the reuslt 
curl_close($ch); 
+0

由於它的工作,不知道我怎麼忘了呢:) – Vivek 2014-09-26 04:54:55

0

你不初始化捲曲使用這樣的:

<?php 

$myurl = "www.yahoo.com"; 
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $myurl); 
curl_setopt ($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$result= curl_exec ($ch); //execute and get the results 
echo $result; //display the reuslt 
curl_close($ch); 
?>