forzatio Posted February 6, 2007 Share Posted February 6, 2007 Hi there I'm using magpie to parse RSS feeds with php. Some of the RSS's contain lots of duplicate items, is there a way to filter out such duplicate content ? for example: Nice story this is a great example Nice story this is a great example Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 6, 2007 Share Posted February 6, 2007 Put each story in an array, and use array_unique Quote Link to comment Share on other sites More sharing options...
forzatio Posted February 6, 2007 Author Share Posted February 6, 2007 foreach ($rss->items as $item) { $description = $item[description]; $url = $item[link]; $title = $item[title]; $array = array($title); $array_unique = array_unique($array); foreach ($array_unique as $value) { echo "$value<br><br>"; } } I tried it like this, but I still get duplicate titles. Quote Link to comment Share on other sites More sharing options...
forzatio Posted February 6, 2007 Author Share Posted February 6, 2007 foreach ($rss->items as $item) { $description = $item[description]; $url = $item[link]; $title = $item[title]; $array = array($description); $array_unique = array_unique($array); foreach ($array_unique as $value) { echo "$value<br><br>"; } } I tried it with the description there are also some duplicates left in there, can I do this code above ? it's a foreach in a foreach.. I'm not sure about my code. Quote Link to comment Share on other sites More sharing options...
forzatio Posted February 7, 2007 Author Share Posted February 7, 2007 ok the code above works but it still shows duplicates, there must be something wrong ? Quote Link to comment Share on other sites More sharing options...
forzatio Posted February 7, 2007 Author Share Posted February 7, 2007 Ok another try, with this code I want to get $description, $title and $url into arrays, and then use array_unique (in this example for the $title) with this code it's not giving any output though. <?php require_once 'rss_fetch.inc'; $url = 'http://www.example.com/feed.rss'; $rss = fetch_rss($url); foreach ($rss->items as $item) { $description = array ($item[description]); $url = array ($item[link]); $title = array ($item[title]); $array_unique = array_unique($title); foreach ($array_unique as $value) { echo "$value<br><br>"; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.