我试图把标题,但它完全

时间:2017-05-17 23:54:13

标签: php

$news = htmlspecialchars(file_get_contents("https://www.ethnews.com/rss.xml"), ENT_QUOTES);

echo $news->channel->item[0]->title;

1 个答案:

答案 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;