SimpleXML and PHP Error Handling - Tumblr RSS Example


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <ul>
  2.  
  3. <?php
  4. $rss = @simplexml_load_file('http://thedailywhat.tumblr.com/rss');
  5. if ($rss) {
  6. $i = 0;
  7. foreach ($rss->channel->item as $item) {
  8. if (++$i > 7) {
  9. // stop after 7 items
  10. break;
  11. }
  12. echo "<li><a href='" . $item->link . "'>" . $item->title . "</a></li>\n";
  13. }
  14. } else {
  15. echo "Tumblr is down.";
  16. }
  17. ?>
  18.  
  19. </ul>

URL: http://marshallim.posterous.com/simplexml-and-php-error-handling-tumblr-rss-e

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.