无法从外部XML / RSS读取

时间:2016-05-22 15:52:43

标签: php rss

似乎没有读取外部URL,因此未检索到该值。我可以知道为什么我的代码不起作用吗?

function GetFeed($url){
    $feed = simplexml_load_file($url);
    $feed_array = array();
    foreach($feed->channel->item as $story){
        $story_array = array (
                              'title' => $story->title,
                              'description' => $story->description
        );

        array_push($feed_array, $story_array);
    }

    return $feed_array;
}


$url = 'http://www.channelnewsasia.com/rss/latest_cna_sg_rss.xml';
$news = GetFeed($url);
echo $news[0]['title'];

0 个答案:

没有答案