从合并的 RSS 提要中计算项目标签

Count item tags from merged rss feed

我正在尝试从 RSS 提要列表中计算标题标签。

$urls = "http://www.engadget.com/rss.xml";
$xml = simplexml_load_file($urls);
$tags = array();
foreach($xml->channel->item as $item) {
  $children = $item->title;
  foreach ($children as $node) {
    $tags[] = $node->getName();
  }
}
$count= array_count_values($tags);

echo '<pre>';
print_r($count);

按照上面的方法做...它可以工作,但是如果我有多个 URL 怎么办。我该怎么做?

将 url 放在一个数组中,然后在 urls 数组周围 foreach 基本上做你已经在做的事情

$urls = ["http://www.engadget.com/rss.xml","http://www.engadget.com/rss.xml"];

$tags = array();
foreach ( $urls as $url ) {
    $xml = simplexml_load_file($url);
    foreach($xml->channel->item as $item) {
        $children = $item->title;
        foreach ($children as $node) {
            $tags[] = $node->getName();
        }
    }
}

$count= array_count_values($tags);

echo '<pre>';
print_r($count);