卷曲输出未显示

时间:2014-09-25 04:54:15

标签: php curl output

以下是我的代码,但它没有显示输出。现在我暂时将yahoo.com显示为curl输出,但我的实际输出网址不同。谁能告诉我代码中的问题是什么?

<?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);
?>

2 个答案:

答案 0 :(得分: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);

答案 1 :(得分: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);
 ?>