Posted By

manavecplan on 03/28/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

clacwebstudio


A Better Twitter Feed for Your Web Site


 / Published in: PHP
 

URL: http://bavotasan.com/tutorials/a-better-twitter-feed-for-your-web-site/#comment-8534

  1. <ul>
  2. <?php
  3. $feedURL = "http://twitter.com/statuses/user_timeline/68559295.rss"; // change to your feed URL
  4. $doc = new DOMDocument();
  5. $doc->load($feedURL);
  6. $arrFeeds = array();
  7. foreach ($doc->getElementsByTagName('item') as $node) {
  8. $itemRSS = array (
  9. 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
  10. );
  11. array_push($arrFeeds, $itemRSS);
  12. }
  13. $limit = 5;
  14. for($x=0;$x<$limit;$x++) {
  15. $title = str_replace('bavotasan: ', '', $arrFeeds[$x]['title']);
  16. $str = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\">\\0</a>", $title);
  17. $pattern = '/[#|@][^\s]*/';
  18. preg_match_all($pattern, $str, $matches);
  19.  
  20. foreach($matches[0] as $keyword) {
  21. $keyword = str_replace(")","",$keyword);
  22. $link = str_replace("#","%23",$keyword);
  23. $link = str_replace("@","",$keyword);
  24. if(strstr($keyword,"@")) {
  25. $search = "<a href=\"http://twitter.com/$link\">$keyword</a>";
  26. } else {
  27. $link = urlencode($link);
  28. $search = "<a href=\"http://twitter.com/#search?q=$link\" class=\"grey\">$keyword</a>";
  29. }
  30. $str = str_replace($keyword, $search, $str);
  31. }
  32. echo '<li>'.$str.'</li>';
  33. }
  34. ?>
  35. </ul>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: blueocto on April 8, 2011

You can no longer use this method as Twitter has stopped the use of RSS feeds

See more here : http://support.twitter.com/groups/31-twitter-basics/topics/107-my-profile-account-settings/articles/15361-how-to-find-your-rss-feed

You need to login to post a comment.