<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Witslog Wiki &#187; XML</title>
	<atom:link href="http://witslog.com/wiki/category/technical/xml/feed" rel="self" type="application/rss+xml" />
	<link>http://witslog.com/wiki</link>
	<description>Technical Log</description>
	<lastBuildDate>Fri, 14 May 2010 06:17:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Read RSS feed XML using CURL in PHP</title>
		<link>http://witslog.com/wiki/technical/php/code-php/read-rss-feed-xml-using-curl-in-php</link>
		<comments>http://witslog.com/wiki/technical/php/code-php/read-rss-feed-xml-using-curl-in-php#comments</comments>
		<pubDate>Wed, 17 Mar 2010 10:55:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Code]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://witslog.com/wiki/?p=106</guid>
		<description><![CDATA[// create a new cURL resource
$ch = curl_init();
$url = &#8220;http://witslog.com/wiki/?feed=rss2&#8243;;
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);  // you have to set the url of the website of which you want to get the rss data
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass...]]></description>
			<content:encoded><![CDATA[<p>// create a new cURL resource</p>
<p>$ch = curl_init();<br />
$url = &#8220;http://witslog.com/wiki/?feed=rss2&#8243;;</p>
<p>// set URL and other appropriate options</p>
<p>curl_setopt($ch, CURLOPT_URL, $url);  // you have to set the url of the website of which you want to get the rss data<br />
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<br />
curl_setopt($ch, CURLOPT_HEADER, 0);</p>
<p>// grab URL and pass it to the browser<br />
$data = curl_exec($ch);</p>
<p>// close cURL resource, and free up system resources<br />
curl_close($ch);</p>
<p>//Now work with SimpleXmlElement. This is core php xml class. The SimpleXML extension provides a very simple and easily usable    toolset to convert XML to an object that can be processed with    normal property selectors and array iterators.</p>
<p>$xml = new SimpleXmlElement($data, LIBXML_NOCDATA);</p>
<p>//check either it is RSS feeder or ATOM Feeder. Rss feeder have channel node while in Atom feeder you see entry node. Generally each feeder have their defined channel.</p>
<p>if(isset($xml-&gt;channel))<br />
{<br />
parseRSS($xml);<br />
}<br />
if(isset($xml-&gt;entry))<br />
{<br />
parseAtom($xml);<br />
}</p>
<p>//This is for rss Feeder<br />
function parseRSS($xml)<br />
{<br />
echo &#8220;&lt;strong&gt;&#8221;.$xml-&gt;channel-&gt;title.&#8221;&lt;/strong&gt;&#8221;;<br />
$cnt = count($xml-&gt;channel-&gt;item);<br />
for($i=0; $i&lt;$cnt; $i++)<br />
{<br />
$url     = $xml-&gt;channel-&gt;item[$i]-&gt;link;<br />
$title     = $xml-&gt;channel-&gt;item[$i]-&gt;title;<br />
$desc = $xml-&gt;channel-&gt;item[$i]-&gt;description;</p>
<p>echo &#8216;&lt;a href=&#8221;&#8216;.$url.&#8217;&#8221;&gt;&#8217;.$title.&#8217;&lt;/a&gt;&#8217;.$desc.&#8221;;<br />
}<br />
}</p>
<p>//This is for XML Feeder<br />
function parseAtom($xml)<br />
{<br />
echo &#8220;&lt;strong&gt;&#8221;.$xml-&gt;author-&gt;name.&#8221;&lt;/strong&gt;&#8221;;<br />
$cnt = count($xml-&gt;entry);<br />
for($i=0; $i&lt;$cnt; $i++)<br />
{<br />
$urlAtt = $xml-&gt;entry-&gt;link[$i]-&gt;attributes();<br />
$url    = $urlAtt['href'];<br />
$title     = $xml-&gt;entry-&gt;title;<br />
$desc    = strip_tags($xml-&gt;entry-&gt;content);</p>
<p>echo &#8216;&lt;a href=&#8221;&#8216;.$url.&#8217;&#8221;&gt;&#8217;.$title.&#8217;&lt;/a&gt;&#8217;.$desc.&#8221;;<br />
}<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://witslog.com/wiki/technical/php/code-php/read-rss-feed-xml-using-curl-in-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

