$news = htmlspecialchars(file_get_contents("https://www.ethnews.com/rss.xml"), ENT_QUOTES);
echo $news->channel->item[0]->title;
答案 0 :(得分:1)
您可能想要使用simplexml_load_file(),即:
$url = "https://www.ethnews.com/rss.xml";
$feed = simplexml_load_file($url);
foreach($feed->channel->item as $story) {
echo $story->title;
# other options :
# echo $story->desc;
# echo $story->link;
# echo $story->date;
}
如果您只需要第一个标题,可以使用:
$url = "https://www.ethnews.com/rss.xml";
$feed = simplexml_load_file($url);
echo $feed->channel->item[0]->title;