Php 如何像我的页面中的原始xml一样正确地回显来自google新闻的rss xml内容?

Php 如何像我的页面中的原始xml一样正确地回显来自google新闻的rss xml内容?,php,xml,xml-parsing,Php,Xml,Xml Parsing,我用这个代码在我的网站上显示IG新闻,但我总是得到它显示的每一条新闻,我不知道为什么会发生,有人能帮忙吗 $xml = simplexml_load_file('https://news.google.com.mx/news/feeds?hl=es&gl=mx&q=realmadrid&um=1&ie=UTF-8&output=rss'); print_r($xml); foreach ($xml as $status) { $description =

我用这个代码在我的网站上显示IG新闻,但我总是得到它显示的每一条新闻,我不知道为什么会发生,有人能帮忙吗

$xml = simplexml_load_file('https://news.google.com.mx/news/feeds?hl=es&gl=mx&q=realmadrid&um=1&ie=UTF-8&output=rss');
print_r($xml);
foreach ($xml as $status) {

$description = $status->item->description;


echo "$description <br> ";

}

您必须解析item标记

$data = file_get_contents('https://news.google.com.mx/news/feeds?hl=es&gl=mx&q=realmadrid&um=1&ie=UTF-8&output=rss');
 $xml_data = simplexml_load_string($data);
 $items = $xml_data->xpath('channel/item');
foreach ($items as $item) {
   echo "title" . $item->title;
}

它的编码速度很快,所以如果有任何问题,请给我回信;)

如果有人帮助我,我会在检查所有代码后得到以下信息:

$data = file_get_contents('https://news.google.com.mx/news/feeds?hl=es&gl=mx&q=realmadrid&um=1&ie=UTF-8&output=rss');

$xml = new SimpleXMLElement($data);
$channel = array();
$channel['title']       = $xml->channel->title;

foreach ($xml->channel->item as $item)
{

    //echo $article['title'] = $item->title;
    //echo $article['link'] = $item->link;
    echo $article['pubDate'] = $item->pubDate;
    echo $article['description'] = (string) trim($item->description);

}

我得到一个致命错误:调用未定义的函数SimpleXMLElement,我不知道该怎么办,请再次帮助。这是我的错误,我的PHP版本是从SVN编译的,所以我有SimpleXMLElement,你必须加载它,这是我文章的新编辑。
$data = file_get_contents('https://news.google.com.mx/news/feeds?hl=es&gl=mx&q=realmadrid&um=1&ie=UTF-8&output=rss');

$xml = new SimpleXMLElement($data);
$channel = array();
$channel['title']       = $xml->channel->title;

foreach ($xml->channel->item as $item)
{

    //echo $article['title'] = $item->title;
    //echo $article['link'] = $item->link;
    echo $article['pubDate'] = $item->pubDate;
    echo $article['description'] = (string) trim($item->description);

}