dongyimeng3764 2014-02-14 07:16
浏览 56
已采纳

从API获取数据[关闭]

I'm trying to extract data from the Api link with Curl. The problem is that my link have no fields posted. I have tried this but I got an error:

Notice: Undefined variable: xml in C:\wamp\www\OOP PHP\GetHtml.php on line 17

The code is as given below:

$handle=curl_init();
$url="https://www.domain.com/api/list/0/";
curl_setopt($handle, CURLOPT_URL, $url);

$result = curl_exec($handle);
//$xml=simplexml_load_string($result);
//$json=json_encode($xml);
//$array=json_decode($json,TRUE);

curl_close($handle);

print_r($xml);

I also tried with 'file_get_html' still not working, if there is a good solution please help me.

p.s: After 4 hours of searching everyone was using 'file_get_html' and it's working perfectly but not always, and also i've found a solution using 'HttpSocket' in Cakephp, and as i'm just a novice in Cakephp i can't work with it.

Sorry i'm so damn sleepy !!!

  • 写回答

1条回答 默认 最新

  • douzhenqun1271 2014-02-14 07:17
    关注

    The file_get_contents() way..

    <?php
    $data=file_get_contents('http://mangaeden.com/api/list/0');
    $data1=json_decode($data,true);
    echo "<pre>";
    print_r($data1);
    

    The cURL way..

    <?php
    $handle=curl_init();
    $url="http://mangaeden.com/api/list/0";
    curl_setopt($handle, CURLOPT_URL, $url);
    curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($handle);
    $data=json_decode($result,true);
    curl_close($handle);
    print_r($data);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看