How to get links from feed using php

Hello, following script is getting all urls and tiles from the feeds of the blog. If we want display the all urls and titles at your website then we get the information from below script:

function getlinks() {

$xml= "http://anillabs.com/feed/";

$xmlDoc = new DOMDocument();

$xmlDoc->load($xml);

//get elements from "<channel>"

$channel=$xmlDoc->getElementsByTagName('channel')->item(0);

$channel_title = $channel->getElementsByTagName('title')

->item(0)->childNodes->item(0)->nodeValue;

$channel_link = $channel->getElementsByTagName('link')

->item(0)->childNodes->item(0)->nodeValue;

$channel_desc = $channel->getElementsByTagName('description')

->item(0)->childNodes->item(0)->nodeValue;

$result='';

//get and output "<item>" elements

$x=$xmlDoc->getElementsByTagName('item');

for ($i=0; $i<=7; $i++)

{

$item_title=$x->item($i)->getElementsByTagName('title')

->item(0)->childNodes->item(0)->nodeValue;

$item_link=$x->item($i)->getElementsByTagName('link')

->item(0)->childNodes->item(0)->nodeValue;

$item_desc=$x->item($i)->getElementsByTagName('description')

->item(0)->childNodes->item(0)->nodeValue;

$result .= ("<p><a target="_blank" href='" . $item_link

. "'>" . $item_title . "</a>");

$result .= ("<br />");

$result .= ("</p>");

}

return $result;

}
?>

We can see the live demo at  @ http://labs.anillabs.com/

Thank you.

Anil Kumar Panigrahi

With more than 10 years experience in PHP and Founder of Anil Labs, a blog for PHP and related posts. contributed posts regarding CodeIgniter, CakePHP and Learn PHP online ... Contact : [email protected]

You may also like...

3 Responses

  1. useful .. post this on Developer zone http://dzone.com at right category

  1. December 24, 2009

    […] Excerpt from: How to get links from feed using php « ANIL KUMAR PANIGRAHI 's Blog […]

  2. September 16, 2011

    […] In have created this post with using my previous posts. 1) How to get links from feed using php http://www.anil2u.info/2009/12/how-to-get-links-from-feed-using-php/ 2) How to clean a string using php code […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.