Display Most Recent Twitter Entry


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



Copy this code and paste it in your HTML
  1. <?php
  2. // Your twitter username.
  3. $username = "TwitterUsername";
  4. // Prefix - some text you want displayed before your latest tweet.
  5. // (HTML is OK, but be sure to escape quotes with backslashes: for example href=\"link.html\")
  6. $prefix = "";
  7. // Suffix - some text you want display after your latest tweet. (Same rules as the prefix.)
  8. $suffix = "";
  9. $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1";
  10. function parse_feed($feed) {
  11. $stepOne = explode("<content type=\"html\">", $feed);
  12. $stepTwo = explode("</content>", $stepOne[1]);
  13. $tweet = $stepTwo[0];
  14. $tweet = str_replace(”&lt;”, “<”, $tweet);
  15. $tweet = str_replace(”&gt;”, “>”, $tweet);
  16. return $tweet;
  17. }
  18. $twitterFeed = file_get_contents($feed);
  19. echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);
  20. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.