使用 PHP 获取 xml 文件时遇到问题


Trouble with getting an xml file with PHP

当我 http://feeds.feedburner.com/Koreus-articles 查看此页面的源代码时,它按预期显示源代码,一个干净的xml文件

但是当我尝试这样做时:

<?php
    $content = file_get_contents('http://feeds.feedburner.com/Koreus-articles');
    echo $content;
?>

我得到了一件可怕的事情:http://pastebin.com/s263M6sC 我只是不明白刚刚发生的事情。

file_get_contents() 适用于任何其他简单页面,例如 www.example.com,只是不适用于该 xml 文件。

任何帮助表示赞赏,谢谢!

只需将file_get_contents()调用更改为simplexml_load_file(),然后就可以使用 print_r 输出整个对象:

$content = simplexml_load_file('http://feeds.feedburner.com/Koreus-articles');
echo "<pre>";
print_r($content);
echo "</pre>";