0

Imaging i have a RSS feed from a website that contains the lastest news of that website,

Like this:

http://example.com/feed

Now, i want to get the last news url from this feed address.

Like this :

http://example.com/post/555.php
http://example.com/post/554.php
http://example.com/post/553.php
http://example.com/post/552.php
http://example.com/post/551.php
http://example.com/post/550.php

How to get list of urls with a limit of (for example) 25 urls In PHP ?

Cab
  • 121
  • 1
  • 1
  • 12
  • Maybe this will point you in the right direction: http://www.w3schools.com/php/php_ajax_rss_reader.asp or this: http://stackoverflow.com/questions/250679/best-way-to-parse-rss-atom-feeds-with-php – Michael Bellamy Jul 24 '14 at 11:32
  • @MichaelBellamy i don't need Ajax code, Just PHP code and Echo out Last URLS . – Cab Jul 24 '14 at 11:34
  • 1
    An RSS feed will return an XML file, so take a look at reading the XML so you can limit the number of feeds it returns. A quick search found this: http://bavotasan.com/2010/display-rss-feed-with-php/ – Michael Bellamy Jul 24 '14 at 11:36

1 Answers1

0

It can be done by using this code :

$rss = new DOMDocument();
$rss->load('http://wordpress.org/news/feed/');
$feed = array();

foreach ($rss->getElementsByTagName('item') as $node) {
    $item = array (
        'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
    );
    array_push($feed, $item);
}

$limit = 5;

for($x=0;$x<$limit;$x++) {
    echo $link = $feed[$x]['link'];
}
Kevin
  • 41,694
  • 12
  • 53
  • 70
Cab
  • 121
  • 1
  • 1
  • 12