Simple Twitter RSS Processing

I required a simple feed from Twitter into www.MindOver-matter.co.uk/news.php. There are numerous examples around but a lot of them are very convoluted. Below is an simple code example. The function could of course be modifed to be generic whereby user info etc would be passed in.

<?php

function parse_cache_feed($usernames, $limit) {
  $feed = "http://twitter.com/statuses/user_timeline/130211322.rss";
  $xml = new SimpleXMLElement(file_get_contents($feed));
  if (count($xml->channel->item) == 0)  {
?>
          <p class="tweet">
              Sorry but failed to connect to Twitter for latest updates,
              it is probably busy so try again later.
              Or look <a href="http://www.twitter.com/MindOverMatter8">here</a>
          </p>
<?php
  } else {
      foreach ($xml->channel->item as $item) {
          ?>
          <div class="calendar">
             <div class="calendar-month">
                  <?php echo date("M",strtotime($item->pubDate)) ?>
             </div>
             <div class="calendar-day">
                  <?php echo date("d",strtotime($item->pubDate)) ?>
             </div>
          </div>
          <p>
            <?php echo str_replace("MindOverMatter8:","",$item->description); ?>
          </p>
<?php
      }
  }
} 

?>
Development

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments are closed.