Posted By

selfmadepsyche on 02/17/09


Tagged

wordpress


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

VaiT
Bluewall
vali29


Display Most Recent Twitter Entry


 / Published in: PHP
 

  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  

You need to login to post a comment.