Location: PHPKode > scripts > ABC_RSS > documentation.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Class ABC_RSS</title>
<style type="text/css">
body {
	background-color: #FFFFFF;
	padding: 20px; 
}
code {
	display: block;
	padding:10px;
	border: 1px dashed #CCC;
	background-color: #ECFCFF;
}
</style>
</head>
<body>
<h1>Class ABC_RSS </h1>
<p>&nbsp;</p>
<p>This class has two public setter methods which take arrays as parameters. The class parses the
  arrays for all required and all optional RSS 2.0 elements. Additional namespaces are not
  supported in this version. </p>
<p>The class attempts to translate input characters into html entities in most cases, but it
  does tolerate (X)HTML markup in 'description' tags, and wraps the content of description
  tags in a CDATA section. It also enforces integer values where integer values are expected,
  and enforces required attributes and sub-elements in optional elements. </p>
<p>The output XML can be written to file, or displayed in a browser, and it is also possible
  to &quot;force&quot; a browser to download the XML file rather than to display it. </p>
<p>&nbsp;</p>
<p><code><strong>@author</strong> Richard Lucas &lt;hide@address.com&gt;<br />
  <strong>@category</strong> RSS<br />
  <strong>@version</strong> 0.1<br />
  <strong>@copyright</strong> Copyright (c) 2010 Richard Lucas <br />
  <strong>@example</strong> example.php<br />
  <strong>@license</strong> http://www.opensource.org/licenses/mit-license.php<br />
  <strong>@link</strong> http://cyber.law.harvard.edu/rss/rss.html<br />
  <strong>@todo</strong> Add namespacing</code></p>
<p>&nbsp;</p>
<h2>Example 1 </h2>
<p>The first example demonstrates an RSS feed made to share a band's demo recordings:</p>
<code> require_once( 'ABC_RSS.php' );<br />
<br />
<br />
$rss = new ABC_RSS();<br />
<br />
<br />
$channel =array();<br />
$channel['title']           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='Band Name';<br />
$channel['link']           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='http://www.band-name.dom/'; <br />
$channel['description'] ='This is our latest demo set.'; <br />
$channel['language']       &nbsp;&nbsp;&nbsp;='en-us'; <br />
$channel['copyright']      &nbsp;&nbsp;='Copyright 2010-2012, Band-Name'; <br />
$channel['webMaster']      &nbsp;&nbsp;='hide@address.com (Jane Doe)';<br />
<br />
$channel['pubDate']        &nbsp;&nbsp;&nbsp;&nbsp;=date( DATE_RSS ); <br />
$channel['generator']      &nbsp;&nbsp;='ABC_RSS PHP Class'; <br />
$channel['docs']           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='http://blogs.law.harvard.edu/tech/rss'; <br />
<br />
$channel['category'] =array();<br />
$channel['category'][] =array( 'content' =&gt;'Rock', 'domain'  =&gt;'genre' );<br />
$channel['category'][] =array( 'content' =&gt;'Folk', 'domain'  =&gt;'genre' ); <br />
<br />
$rss-&gt;set_channel( $channel );<br />
<br />
<br />
$item =array(); <br />
$item['title']       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='Love Machine'; <br />
$item['description'] ='This is a power ballad evocative of MC Bubblicious Fish-eyes.';<br />
$item['link']&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        ='http://www.band-name.dom/band/songs/love_machine.html<br />
<br />
$item['enclosure'] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=array(); <br />
$item['enclosure']['url']&nbsp;&nbsp;&nbsp;    ='http://www.band-name.dom/band/songs/love_machine.mp3';<br />
$item['enclosure']['length'] ='12216320'; <br />
$item['enclosure']['type']&nbsp;&nbsp;   ='audio/mpeg';<br />
<br />
$item['category'] = array(); <br />
$item['category'][] =array( 'content' =&gt;'Rock', 'domain'  =&gt;'genre' );<br />
<br />
$rss-&gt;set_item( $item );<br />
<br />
<br />
$item =array(); <br />
$item['title']       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='Mud Puppet Square Dance'; <br />
$item['description'] ='A folksy taste of Americana';<br />
$item['link']&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        ='http://www.band-name.dom/band/songs/mud_puppet.html<br />
<br />
$item['enclosure'] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=array(); <br />
$item['enclosure']['url']&nbsp;&nbsp;&nbsp;    ='http://www.band-name.dom/band/songs/mud_puppet.mp3';<br />
$item['enclosure']['length'] ='14005740'; <br />
$item['enclosure']['type']&nbsp;&nbsp;   ='audio/mpeg';<br />
<br />
$item['category'] = array(); <br />
$item['category'][] =array( 'content' =&gt;'Folk', 'domain'  =&gt;'genre' );<br />
<br />
$rss-&gt;set_item( $item );<br />
<br />
<br />
$rss-&gt;export();</code>
<p>Instantiate the object...</p>
<p><code>$rss =new ABC_RSS();</code></p>
<p>Create an associative array and populate it with the elements you want for the channel.
  You must supply it with at least the required elements, or you will get an error... </p>
<code>$channel = array(); <br />
$channel['link']           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='http://www.band-name.dom/'; <br />
$channel['description'] ='This is our latest demo set.'; <br />
$channel['language']       &nbsp;&nbsp;&nbsp;='en-us'; <br />
$channel['copyright']      &nbsp;&nbsp;='Copyright 2010-2012, Band-Name'; <br />
$channel['webMaster']      &nbsp;&nbsp;='hide@address.com (Jane Doe)'; <br />
$channel['pubDate']        &nbsp;&nbsp;&nbsp;&nbsp;=date( DATE_RSS ); <br />
$channel['generator']      &nbsp;&nbsp;='ABC_RSS PHP Class'; <br />
$channel['docs']           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='http://blogs.law.harvard.edu/tech/rss';</code>
<p>The &lt;category&gt; element must be handled differently from other elements, since more than one category element is allowed. For every category element, a subarray is added to the <strong><samp>$channel['category']</samp></strong> element. The 'domain' attribute is optional, and the subarray element key 'domain' may be ommitted. For example, if you wanted to add the following category elements to the channel portion of your feed:</p>
<p><code>&lt;category domain='genre'&gt;Rock&lt;/category&gt;<br />
  &lt;category domain='genre'&gt;Folk&lt;/category&gt;</code></p>
<p>Then you would set the values like so:</p>
<p><code>$channel['category'] =array();<br />
  $channel['category'][] =array( 'content' =&gt;'Rock', 'domain'  =&gt;'genre' );<br />
  $channel['category'][] =array( 'content' =&gt;'Folk', 'domain'  =&gt;'genre' );</code></p>
<p>Set the channel data...</p>
<p><code>$rss-&gt;set_channel( $channel ); </code></p>
<p>At least one item is required. Create a new item array for every item you want to add...</p>
<p><code>$item = array(); <br />
  $item['title']       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='Love Machine'; <br />
  $item['description'] ='This is a power ballad evocative of MC Bubblicious Fish-eyes.';<br />
  $item['link']&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        ='http://www.band-name.dom/band/songs/love_machine.html</code></p>
<p>Next is an example of an element with attributes. In such case, assign the element name an array value,
  and the elements of this sub-array will map to the attributes of the given element.</p>
<p><code>$item['enclosure'] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=array(); <br />
  $item['enclosure']['url']&nbsp;&nbsp;&nbsp;    ='http://www.band-name.dom/band/songs/love_machine.mp3';<br />
  $item['enclosure']['length'] ='12216320'; <br />
  $item['enclosure']['type']&nbsp;&nbsp;   ='audio/mpeg';</code></p>
<p>Set the category (or categories)::</p>
<p><code>$item['category'] =array(); <br />
$item['category'][] =array( 'content' =    &gt;'Rock', 'domain'  =&gt;'genre' );</code> </p>
<p> Then set each item after you have populated it:</p>
<p><code>$rss-&gt;set_item( $item ); </code></p>
<p> The composition of each item can be different. Technically, neither the 'title' nor the
  'description' element are absolutely required, but the specs require that you do use at
  least one or the other. Most RSS parsers and default display schemes will not take kindly
  to a missing 'title' element, however, and it's just good form to make use of both of
  these tags. If you insist on omitting a title, you must provide a description, however,
  and vice versa.</p>
<p>The final step is to call the 'export' function. It can take up to two optional parameters.
  The first parameter determines how the RSS is expressed.</p>
<p>The default method is to send headers telling the browser to expect content type
  'text/xml', and then to exit and dump the XML content into the browser window. I would
  prefer to use a more specific content type, but Firefox will try to download it by default
  if another, more specific content-type is specified. To simply export the RSS to the
  browser window as described, call the export function like so:</p>
<p><code>$rss-&gt;export(); </code></p>
<p>You can attempt to force the browser to download the XML rather than to display it by
  calling the export function and passing it the parameter 'download':</p>
<p><code>$rss-&gt;export('download'); </code></p>
<p>The final option is to write the XML to file and serve it up statically. To do this, call
  the export function and pass it two parameters. The first tells the function to write the
  XML to file, and the second is the full path to the XML file you want it to write. If the
  file does not exist, the function will attempt to create it. You must, of course, have
  write permissions in order to accomplish this:</p>
<p><code>$rss-&gt;export('write','/home/user/htdocs/xml/rss.xml'); </code></p>
<p>&nbsp;</p>
<h2>Example 2</h2>
<p>This is a more advanced example, and it portrays the use of the ABC_RSS class to fetch the latest ten local news items from a MySQL database and then write them to a static XML/RSS feed.</p>
<p><code>require_once( 'ABC_RSS.php' ); <br />
  <br />
  <br />
  $hostname =&quot;host&quot;;<br />
  $database =&quot;database&quot;;<br />
  $username =&quot;username&quot;;<br />
  $password =&quot;password&quot;; <br />
  <br />
  <br />
  $errors =array();<br />
  $destination_file ='home/user/htdocs/xml/local_news.xml'; <br />
  <br />
  <br />
  try { <br />
  &nbsp;&nbsp;<br />
  &nbsp;&nbsp;if ( !$connection =mysql_connect( $hostname, $username, $password ))<br />
  &nbsp;&nbsp;&nbsp;&nbsp;throw new Exception( mysql_error(), mysql_errno() );<br />
  <br />
  &nbsp;&nbsp;if ( !mysql_select_db( $database, $connection ))<br />
  &nbsp;&nbsp;&nbsp;&nbsp;throw new Exception( &quot;Unable to connect to database '$database'.&quot; );<br />
  <br />
  &nbsp;&nbsp;$query =&quot;SELECT `id`, `title`, `description`, `datetime` &quot;.<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;FROM `articles` &quot;.<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;WHERE `scope` = 'local' &quot;.<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;ORDER BY `datetime` DESC &quot;.<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;LIMIT 0, 10&quot;;<br />
  <br />
  &nbsp;&nbsp;if ( !$result =mysql_query( $query, $connection ))<br />
  &nbsp;&nbsp;&nbsp;&nbsp;throw new Exception( mysql_error(), mysql_errno() );<br />
  <br />
  &nbsp;&nbsp;$row_count =@mysql_num_rows( $result ); <br />
  <br />
  &nbsp;&nbsp;if ( $row_count &gt; 0 )<br />
  &nbsp;&nbsp;{<br />
  &nbsp;&nbsp;&nbsp;&nbsp;$rss =new ABC_RSS(); <br />
  <br />
  &nbsp;&nbsp;&nbsp;&nbsp;$channel =array();<br />
  &nbsp;&nbsp;&nbsp;&nbsp;$channel['title']    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='News.dom - All the News You Can Stand';<br />
  &nbsp;&nbsp;&nbsp;&nbsp;$channel['link']           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='http://www.news.dom/';<br />
  &nbsp;&nbsp;&nbsp;&nbsp;$channel['description']&nbsp;&nbsp;&nbsp;    ='The Latest Ten Local News Stories from News.dom';<br />
  &nbsp;&nbsp;&nbsp;&nbsp;$channel['language']       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='en-us';<br />
  &nbsp;&nbsp;&nbsp;&nbsp;$channel['copyright']      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='Copyright 2010-2012, News.dom';<br />
  &nbsp;&nbsp;&nbsp;&nbsp;$channel['managingEditor'] ='hide@address.com (John Smith)';<br />
  &nbsp;&nbsp;&nbsp;&nbsp;$channel['webMaster']      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='hide@address.com (Jane Doe)';<br />
  &nbsp;&nbsp;&nbsp;&nbsp;$channel['pubDate']        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=date(DATE_RSS);<br />
  &nbsp;&nbsp;&nbsp;&nbsp;$channel['generator']      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='ABC_RSS PHP Class';<br />
  &nbsp;&nbsp;&nbsp;&nbsp;$channel['docs']           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='http://blogs.law.harvard.edu/tech/rss';<br />
  &nbsp;&nbsp;&nbsp;&nbsp;$channel['skipHours']      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='0,1,2,3';<br />
  &nbsp;&nbsp;&nbsp;&nbsp;$channel['skipDays']&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;       ='Saturday';<br />
  <br />
  &nbsp;&nbsp;&nbsp;&nbsp;$channel['category'] =array();<br />
  &nbsp;&nbsp;&nbsp;&nbsp;$channel['category'][] =array( 'content' =&gt;'news', 'domain'  =&gt;'local' );<br />
  <br />
  &nbsp;&nbsp;&nbsp;&nbsp;if ( !$rss-&gt;set_channel( $channel ))<br />
  &nbsp;&nbsp;&nbsp;&nbsp;{<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$errors =&amp;$rss-&gt;errors;<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new Exception( &quot;Failed to set the channel.&quot; );<br />
  &nbsp;&nbsp;&nbsp;&nbsp;} <br />
  <br />
  &nbsp;&nbsp;&nbsp;&nbsp;for ( $i =0 ; $i &lt;$row_count ; $i++ )<br />
  &nbsp;&nbsp;&nbsp;&nbsp;{ <br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$row =mysql_fetch_assoc( $result );<br />
  <br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item =array();<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item['title']       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=$row['title']; <br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item['description'] =$row['description']; <br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item['link']        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=sprintf( &quot;http://www.news.dom/articles/?id=%d&quot;, $row['id'] );<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item['pubDate']     &nbsp;&nbsp;&nbsp;&nbsp;=date( DATE_RSS, strtotime( $row['datetime'] ));<br />
  <br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item['category'] =array();<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item['category'][] =array( 'content' =&gt;'news', 'domain'  =&gt;'local' ); <br />
  <br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( !$rss-&gt;set_item( $item ))<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$errors =&amp;$rss-&gt;errors;<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new Exception( &quot;Failed to set the item.&quot; );<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
  &nbsp;&nbsp;&nbsp;&nbsp;} <br />
  <br />
  &nbsp;&nbsp;&nbsp;&nbsp;if ( !$rss-&gt;export( 'write', $destination_file ))<br />
  &nbsp;&nbsp;&nbsp;&nbsp;{<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$errors =&amp;$rss-&gt;errors;<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new Exception( &quot;Failed to write the XML to file.&quot; );<br />
  &nbsp;&nbsp;&nbsp;&nbsp;}<br />
  &nbsp;&nbsp;}<br />
  <br />
  &nbsp;&nbsp;else throw new Exception( &quot;No articles were found in the database.&quot; );<br />
  } <br />
  <br />
  catch ( Exception $e ) { $errors[] =$e-&gt;getMessage(); } <br />
  <br />
  if ( count( $errors ) &gt; 0 ) <br />
  &nbsp;&nbsp;foreach ( $errors as $error )<br />
  &nbsp;&nbsp;&nbsp;&nbsp;printf( &quot;&lt;p&gt;%s&lt;/p&gt;&quot;, $error ); <br />
  <br />
  else<br />
  &nbsp;&nbsp;exit ( &quot;&lt;p&gt;The XML file was written without errors.&lt;/p&gt;&quot; );</code></p>
<p>In Example 2 there are two optional elements which are handled slightly differently than the elements
  shown above. The elements &lt;skipHours&gt; and &lt;skipDays&gt; describe to feed aggregators the hours
  and days upon which the XML cannot be refreshed. The &lt;skipHours&gt; element takes up to 23 sub-elements, each named &lt;hour&gt;, and each containing an integer value between 0 and 24
  inclusive representing the hours of the day. To instruct aggregators not to attempt to
  refresh the feed between the hours of midnight and four o'clock in the morning, for
  example, you might try the following:</p>
<code>&lt;skipHours&gt; <br />
&nbsp;&nbsp;&lt;hour&gt;0&lt;/hour&gt; <br />
&nbsp;&nbsp;&lt;hour&gt;1&lt;/hour&gt; <br />
&nbsp;&nbsp;&lt;hour&gt;2&lt;/hour&gt; <br />
&nbsp;&nbsp;&lt;hour&gt;3&lt;/hour&gt; <br />
&lt;/skipHours&gt;</code>
<p> Obviously, you cannot build the &lt;skipHours&gt; element the same way that you build other elements, because you cannot
  have multiple keys with the name 'hour' in the array. The &lt;skipDays&gt; element is similar,
  only instead of integers it takes the name of the days the aggregaotrs should skip:</p>
<p><code>&lt;skipDays&gt;<br />
  &nbsp;&nbsp;&lt;day&gt;Saturday&lt;/day&gt;<br />
  &lt;/skipDays&gt; </code> </p>
<p> But we still have the problem of a repeating element name which cannot be represented as
  a repeating array key, since each successive array element having the same key, 'day',
  would simply overwrite the previous one.</p>
<p>So, for these two optional elements, the solution is very simple. You'll pass the repeating
  XML values into one array value using a comma-separated list. In order to recreate the
  &lt;skipHours&gt; structure that you see above, you would create a corresponding array element and
  feed in the comma-delimited string:</p>
<p> <code>$channel['skipHours'] = '0,1,2,3'; </code></p>
<p>And for the &lt;skipDays&gt; element:</p>
<p><code>$channel['skipDays'] = 'Saturday'; </code></p>
<p>&nbsp;</p>
<h2>Example 3</h2>
<p>Here is an example of how it might look if you created an RSS with every required and optional element.</p>
<p><code> require_once( 'ABC_RSS.php' ); <br />
  <br />
  $destination_file ='rss.xml'; <br />
  <br />
  $rss = new ABC_RSS(); <br />
  <br />
  try { <br />
  <br />
  &nbsp;&nbsp; // All possible channel elements <br />
  <br />
  &nbsp; $channel =array(); <br />
  &nbsp; $channel['title']          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='News.dom'; <br />
  &nbsp; $channel['link']           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='http://www.news.dom/'; <br />
  &nbsp; $channel['description']    &nbsp;&nbsp;&nbsp;='All the News You Can Stand'; <br />
  &nbsp; $channel['language']       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='en-us'; <br />
  &nbsp; $channel['copyright']      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='Copyright 2010-2012, News.dom'; <br />
  &nbsp; $channel['managingEditor'] ='hide@address.com (John Smith)'; <br />
  &nbsp; $channel['webMaster']      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='hide@address.com (Jane Doe)'; <br />
  &nbsp; $channel['pubDate']        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=date( DATE_RSS ); <br />
  &nbsp; $channel['lastBuildDate']  &nbsp;=date( DATE_RSS ); <br />
  <br />
  &nbsp; $channel['category'] =array(); <br />
  &nbsp;&nbsp;$channel['category'][] =array( 'content' =&gt;'news', 'domain'  =&gt;'local,regional,national,world' );<br />
  &nbsp;&nbsp;$channel['category'][] =array( 'content' =&gt;'sports', 'domain'  =&gt;'local,regional,national' );<br />
  &nbsp;&nbsp;$channel['category'][] =array( 'content' =&gt;'entertainment', 'domain'  =&gt;'local,regional,national' );<br />
  <br />
  &nbsp; $channel['generator'] ='ABC_RSS PHP Class'; <br />
  &nbsp; $channel['docs']      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='http://blogs.law.harvard.edu/tech/rss'; <br />
  <br />
  &nbsp; $channel['cloud'] = array(); <br />
  &nbsp; $channel['cloud']['domain']            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='rpc.news.dom'; <br />
  &nbsp; $channel['cloud']['port']              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='80'; <br />
  &nbsp; $channel['cloud']['path']              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='/RPC2'; <br />
  &nbsp; $channel['cloud']['registerProcedure'] ='pingMe'; <br />
  &nbsp; $channel['cloud']['protocol']          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='soap';<br />
  <br />
  &nbsp; $channel['ttl'] = '60'; <br />
  &nbsp;<br />
  &nbsp; $channel['image'] =array(); <br />
  &nbsp; $channel['image']['url']    &nbsp;&nbsp;&nbsp;='http://www.news.dom/logo.jpg'; <br />
  &nbsp; $channel['image']['title']  &nbsp;='News.dom'; <br />
  &nbsp; $channel['image']['link']   &nbsp;&nbsp;='http://www.news.dom/'; <br />
  &nbsp; $channel['image']['width']  &nbsp;='88'; <br />
  &nbsp; $channel['image']['height'] ='31'; <br />
  <br />
  &nbsp; $channel['rating'] ='(PICS-1.1 &quot;http://www.gcf.org/v2.5&quot; '. <br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'l r (suds 0.5 density 0 color/hue 1) '. <br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'r (subject 2 density 1 color/hue 1))'; <br />
  <br />
  &nbsp; $channel['textInput'] =array(); <br />
  &nbsp; $channel['textInput']['title']       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='Search'; <br />
  &nbsp; $channel['textInput']['description'] ='Find an article on News.dom'; <br />
  &nbsp; $channel['textInput']['name']        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='q'; <br />
  &nbsp; $channel['textInput']['link']        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='http://www.news.dom/search/'; <br />
  <br />
  &nbsp; $channel['skipHours'] ='0,1,2,3'; <br />
  &nbsp; $channel['skipDays']  &nbsp;='Saturday';<br />
  <br />
  &nbsp; if ( !$rss-&gt;set_channel( $channel )) <br />
  &nbsp; { <br />
  &nbsp;&nbsp;&nbsp; $errors =&amp;$rss-&gt;errors; <br />
  &nbsp;&nbsp;&nbsp; throw new Exception( 'Unable to set the RSS channel.' ); <br />
  &nbsp; } <br />
  <br />
  &nbsp; // All possible item elements <br />
  <br />
  &nbsp; $item =array(); <br />
  &nbsp; $item['title']       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='New Water Park Makes Big Splash in Local Economy'; <br />
  &nbsp; $item['description'] ='Reporter Peter Griffin talks to Bob Smith, the owner-operator '. <br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'of Quahog\'s new attraction, Wetworld.';<br />
  &nbsp; $item['link']        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='http://www.news.dom/headlines/'; <br />
  &nbsp; $item['author']      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;='Peter Griffin'; <br />
  <br />
  &nbsp; $item['category'] =array(); <br />
  &nbsp;&nbsp;$item['category'][] =array( 'content' =&gt;'news', 'domain'  =&gt;'local' );<br />
  &nbsp;&nbsp;$item['category'][] =array( 'content' =&gt;'entertainment', 'domain'  =&gt;'local' );<br />
  <br />
  &nbsp; $item['comments'] ='http://www.news.dom/comments/?article=7836453'; <br />
  <br />
  &nbsp; $item['enclosure'] =array(); <br />
  &nbsp; $item['enclosure']['url']    &nbsp;&nbsp;&nbsp;='http://www.news.dom/video/?id=68737'; <br />
  &nbsp; $item['enclosure']['length'] ='12216320'; <br />
  &nbsp; $item['enclosure']['type']   &nbsp;&nbsp;='video/quicktime'; <br />
  <br />
  &nbsp; $item['guid'] =array(); <br />
  &nbsp; $item['guid']['isPermaLink'] ='true'; <br />
  &nbsp; $item['guid']['content']     &nbsp;&nbsp;&nbsp;&nbsp;='http://www.news.dom/articles/?id=7836453'; <br />
  <br />
  &nbsp; $item['pubDate'] ='Sun, 19 May 2002 15:21:36 GMT'; <br />
  <br />
  &nbsp; if ( !$rss-&gt;set_item( $item )) <br />
  &nbsp; { <br />
  &nbsp;&nbsp;&nbsp; $errors =&amp;$rss-&gt;errors; <br />
  &nbsp;&nbsp;&nbsp; throw new Exception( 'Unable to set the RSS item.' ); <br />
  &nbsp; } <br />
  <br />
  &nbsp;&nbsp;if ( !$rss-&gt;export( 'write', $destination_file )) <br />
  &nbsp; { <br />
  &nbsp;&nbsp;&nbsp; $errors =&amp;$rss-&gt;errors; <br />
  &nbsp;&nbsp;&nbsp; throw new Exception( 'Unable to write the RSS file.' ); <br />
  &nbsp; } <br />
  } <br />
  <br />
  catch ( Exception $e ) { $errors[] =$e-&gt;getMessage(); } <br />
  <br />
  if ( !empty( $errors )) <br />
  &nbsp;	foreach ( $errors as $error ) <br />
  &nbsp;&nbsp;&nbsp;	printf( &quot;&lt;p&gt;%s&lt;/p&gt;&quot;, $error ); <br />
  <br />
  else <br />
  &nbsp;	print '&lt;p&gt;The RSS was created without errors.&lt;/p&gt;'; </code></p>
</body>
</html>
Return current item: ABC_RSS