magicnines.com
  • Home
  • Hosting
    • Budget Hosting
      • Linux Packages
      • Windows Packages
    • Mega Hosting
      • Linux Packages
      • Windows Packages
    • Priority Hosting
    • Reseller Hosting
      • Linux Reseller
      • Windows Reseller
    • VPS Hosting
      • Linux VPS
      • Windows VPS
    • Dedicated Server
      • Linux Server
      • Windows Server
  • Telecom
    • Voice Messaging
    • VOIP Calling
    • Pull SMS Service
      • Short Code
      • Long Code
      • Short code Suffix
    • Bulk SMS
      • International SMS
      • Economy SMS
      • Premium SMS
    • SMS Reseller
      • Economy SMS
      • Premium SMS
  • Design
    • Web 2.0 Design
    • Social Design
      • Orkut API
      • Facebook API
      • Twitter Background
    • Wordpress
    • Ecommerce
    • WAP Portal
    • Web Maintenance
    • Dedicated Hiring
    • Portfolio
  • Promotion
    • Search Engine Optimization
    • PPC Marketing
    • Link Building
    • Content Writing
    • Email Marketing
  • Add on
    • Domain Registration
      • Special Domains
      • Domain Pricing
    • Email Hosting
      • Business Email
      • Gmail Integration
    • Digital Certificats
  • Know Us
    • Company Profile
    • Awards & Rating
    • Our Clients
    • We are Hiring
  • Support
    • Post Ticket
    • Knowledge Base
    • Contact Us
    • Client Area
  • Tech Blog

How to fetch RSS feed using PHP

Posted on August 2nd in PHP Bites

This one is a very simple tutorial which will guide you to insert RSS feed from another website into your website using very little PHP. As you know, PHP 5 introduced the DOM extension to work with XML documents. We will use this DOM extension to do this simple PHP operation.

Check the below simple PHP code. You just need to change the feed URL at code line 3 ( just use your desired link) and the number of posts to display which is in line 14. We used here our WordPress blog feed to show you an example.

<br />
&lt;?php<br />
	$rss = new DOMDocument();<br />
	$rss-&gt;load('http://techblog.magicnines.com/feed/');<br />
	$feed = array();<br />
	foreach ($rss-&gt;getElementsByTagName('item') as $node) {<br />
		$item = array (<br />
			'title' =&gt; $node-&gt;getElementsByTagName('title')-&gt;item(0)-&gt;nodeValue,<br />
			'link' =&gt; $node-&gt;getElementsByTagName('link')-&gt;item(0)-&gt;nodeValue,<br />
			);<br />
		array_push($feed, $item);<br />
	}<br />
	$limit = 5;<br />
	for($x=0;$x&lt;$limit;$x++) {<br />
		$title = str_replace(' &amp; ', ' &amp;amp; ', $feed[$x]['title']);<br />
		$link = $feed[$x]['link'];<br />
		echo '&lt;li&gt;&lt;a href=&quot;'.$link.'&quot; title=&quot;'.$title.'&quot;&gt;'.$title.'&lt;/a&gt;&lt;/li&gt;';<br />
	}<br />
?&gt;<br />

It is even simpler than you thought.

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Leave a Reply

Click here to cancel reply.

CAPTCHA Image
CAPTCHA Audio
Refresh Image

Follow Us!

Follow Us on FacebookFollow Us on TwitterFollow Us on LinkedInFollow Us on SkypeFollow Us on BuzzFollow Us on RSS

Search our blog

Category

  • Company News (1)
  • Domain Registration (2)
  • Fancy Web 2.0 (2)
  • Offers (1)
  • PHP Bites (1)
  • SEO Tricks (1)
  • Soicalization (2)
  • Web Security (1)
  • WordPress (1)

Recent Posts

  • Facebook: Top 10 Satus Updates of 2010
  • Now Facebook drops IE 6 Support for its chat feature
  • Update your latest 3rd Party scripts to prevent hacking
  • Google font API with font directory – learn a little about it
  • After .TV and .Me Google approves CO domain too for International Use

Find Us on Facebook

  • Web Hosting


    Linux Shared Hosting
    Linux Priority Hosting
    Linux Budget Hosting
    Windows Shared Hosting
    Windows Budget Hosting
    Linux Reseller Hosting
    Windows Reseller Hosting

  • Dedicated Server


    Linux VPS Hosting
    Windows VPS Hosting
    Linux Dedicated Server
    Windows Dedicated Server

  • Web Design


    Web 2.0 Design
    WAP Portal Development
    Website Maintenance
    Social Application Design
    Dedicated Hiring
    Ready PHP Products

  • Bulk SMS Service


    Economy Bulk SMS
    Premium Bulk SMS
    International Bulk SMS
    Economy SMS Reseller
    Premium SMS Reseller Shortcode Service

  • Voice Solution


    Fax to Email Service
    Inbound IVR Diling
    Outbound IVR Diling
    Voice Solution Shortcode
    Resale our Voice Solutions

  • Online Marketing


    Search Engine Optimization
    Link Building
    E-mail Marketing
    Search Engine Submission
    Content Writing

  • Addon Services


    Domain Registration
    Digital Certificate
    Business Email Solution
    Gmail Integration Service
    Domain Reseller Programme

  • About Us


    Who We Are
    Clients & Testimonials
    Our Project Portfolio
    Our Tecch Blog
    Career @ Magic Nines
    Contact Us


Blog WebMastered by All in One Webmaster.