Display Tweets From Multiple Users


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

WordPress


Copy this code and paste it in your HTML
  1. <?php
  2. $usernames = "Username Username Username"; // Pull from accounts, separated by a space
  3. $limit = "5"; // Number of tweets to pull in, total.
  4. $show = 1; // Show username? 0 = No, 1 = Yes.
  5.  
  6. $prefix = ""; // This comes before the entire block of tweets.
  7. $prefix_sub = ""; // This comes before each tweet on the feed.
  8. $wedge = ""; // This comes after the username but before the tweet content.
  9. $suffix_sub = "<br>"; // This comes after each tweet on the feed.
  10. $suffix = ""; // This comes after the entire block of tweets.
  11.  
  12. function parse_feed($usernames, $limit, $show, $prefix_sub, $wedge, $suffix_sub) {
  13.  
  14. $usernames = str_replace(" ", "+OR+from%3A", $usernames);
  15. $feed = "http://search.twitter.com/search.atom?q=from%3A" . $usernames . "&rpp=" . $limit;
  16. $feed = file_get_contents($feed);
  17. $feed = str_replace("&", "&", $feed);
  18. $feed = str_replace("<", "<", $feed);
  19. $feed = str_replace(">", ">", $feed);
  20. $clean = explode("<entry>", $feed);
  21. $amount = count($clean) - 1;
  22.  
  23. for ($i = 1; $i <= $amount; $i++) {
  24.  
  25. $entry_close = explode("</entry>", $clean[$i]);
  26. $clean_content_1 = explode("<content type=\"html\">", $entry_close[0]);
  27. $clean_content = explode("</content>", $clean_content_1[1]);
  28. $clean_name_2 = explode("<name>", $entry_close[0]);
  29. $clean_name_1 = explode("(", $clean_name_2[1]);
  30. $clean_name = explode(")</name>", $clean_name_1[1]);
  31. $clean_uri_1 = explode("<uri>", $entry_close[0]);
  32. $clean_uri = explode("</uri>", $clean_uri_1[1]);
  33.  
  34. echo $prefix_sub;
  35. if ($show == 1) { echo "<a href=\"" . $clean_uri[0] . "\">" . $clean_name[0] . "</a>" . $wedge; }
  36. echo $clean_content[0];
  37. echo $suffix_sub;
  38.  
  39. }
  40. }
  41. echo $prefix;
  42. parse_feed($usernames, $limit, $show, $prefix_sub, $wedge, $suffix_sub);
  43. echo $suffix;
  44. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.