php curl_init()无效

时间:2012-04-30 10:50:24

标签: php

我正在尝试使用网址发送短信但是它无效,结果为空这是我的代码

$ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$url);

        /**
        * Ask cURL to return the contents in a variable
        * instead of simply echoing them to the browser.
        */

        //Using Proxy
        // curl_setopt($ch, CURLOPT_PROXY, '212.138.39.84:8080');
        //

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        /**
        * Execute the cURL session
        */
$result = curl_exec ($ch);
                    /**
        * Close cURL session
        */
        curl_close ($ch);


         $result=explode("\n",$result);
         $result=$result[(count($result)-1)];
     $result;
谁能帮助我?

1 个答案:

答案 0 :(得分:3)

试试这个

<?php 

    $ch = curl_init ($url);

     /*
      * Send SMS
      */
      curl_setopt ($ch , CURLOPT_RETURNTRANSFER , TRUE);
      curl_setopt($ch , CURLOPT_TIMEOUT , 30);

     /*
      * Execute command and send sms
      */

     $result = curl_exec ($ch);
?>

你可以写下面的行打印输出

<?php
      echo "<pre>";
      print_r($result); 
      echo "</pre>";
?>

在解析或expload结果后查看输出。