Read xml data from url using curl and php

后端 未结 3 1599
滥情空心
滥情空心 2020-12-30 17:26

I want to read XML data from a URL. I have the URL as follows:

http://www.arrowcast.net/fids/mco/fids.asp?sort=city&city=&number=&airline=&adi=A

<
3条回答
  •  隐瞒了意图╮
    2020-12-30 17:47

    This is the demo of how to get channel id from rss feed of youtube in which i read xml data from url using curl.

    $channel_id = 'XXXXXXXX'; // put the channel id here
    
    //using curl
    $url = 'https://www.youtube.com/feeds/videos.xml?channel_id='.$channel_id.'&orderby=published';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    $response  = curl_exec($ch);
    curl_close($ch);
    
    $response=simplexml_load_string($response);
    $json = json_encode($response);
    $youtube= json_decode($json, true);
    
    $count = 0;
    if(isset($youtube['entry']['0']) && $youtube['entry']['0']!=array())
    {
        foreach ($youtube['entry'] as $k => $v) {
            $yt_vids[$count]['id'] = str_replace('http://www.youtube.com/watch?v=', '', $v['link']['@attributes']['href']);
            $yt_vids[$count]['title'] = $v['title'];
            $count++;
        }
    }
    else
    {
        $yt_vids[$count]['id']=str_replace('http://www.youtube.com/watch?v=', '', $youtube['entry']['link']['@attributes']['href']);
        $yt_vids[$count]['title']=$youtube['title'];
    }
    echo "
    ";
    print_r($yt_vids);
    

提交回复
热议问题