gpt4 book ai didi

php - 如何从 Simplepie(多个)提要中删除重复的帖子

转载 作者:行者123 更新时间:2023-12-04 18:13:54 24 4
gpt4 key购买 nike

我有多个分支站点,它们使用 Simplepie 将他们的 RSS 新闻提要馈送到一个主站点。这很好用。唯一的问题是,有时多个分支机构发布同一篇新闻文章,然后在主站点上显示多篇新闻文章。我将如何删除重复项?

<?php
require_once(ABSPATH .'php/simplepie.inc');
$feed = new SimplePie();

$feed->set_feed_url(array(

'http://www.branch1.com/feed/',
'http://www.branch2.com/feed/',
'http://www.branch3.com/feed/',
'http://www.branch4.com/feed/',

));

$feed->set_favicon_handler('handler_image.php');
$feed->init();
$feed->handle_content_type();


foreach ($feed->get_items() as $property):

// I want this to be unique
echo $property->get_title();

endforeach;
?>

我已经试过了。没有运气。
foreach (array_unique($unique) as $property):

我还尝试进行第二次 foreach 寻找任何匹配的标题。并且只显示旁边有数字 1 或第一场比赛的那些......但它一直给我匹配的数量而不是:

1.Match0
1.Match1 2.Match1 3.Match1
1.Match2 2.Match2
等等等等……
foreach ($feed->get_items() as $property):

$t = $property->get_title();
$match = 0;

foreach ($feed->get_items() as $property2):
$t2 = $property2->get_title();

if ($t == $t2){
$match++;
//echo $match;
}

if ($match <= 2){echo "$match. $t <br/> ";}

endforeach;

endforeach;

最佳答案

尝试使用 将获取的项目放入另一个数组中标题的关键这样重复的标题将在数组中被覆盖。然后你从数组中拉回内容。

$arrFeedStack = array();
foreach ($feed->get_items() as $property):
$arrFeedStack[$property->get_title()] = $property->get_description();
endforeach;

foreach ($arrFeedStack as $item) {
echo $item . <br />;
}

关于php - 如何从 Simplepie(多个)提要中删除重复的帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12090756/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com