【问题标题】:Count item tags from merged rss feed从合并的 rss 提要中计算项目标签
【发布时间】:2021-02-12 17:02:10
【问题描述】:

我正在尝试从 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 的所有标签吗?或者每个 url 的标签计数
  • 我希望它是来自多个 url 的所有标签

标签: php xml rss simplexml


【解决方案1】:

将 urls 放在一个数组中,然后在 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);

【讨论】:

    猜你喜欢
    • 2014-11-02
    • 2013-12-18
    • 2011-05-27
    • 2010-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-20
    • 1970-01-01
    相关资源
    最近更新 更多