Custom Twitter Badge Using PHP


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

Display the number of people following you on Twitter using this custom Twitter badge. The code simply returns a number so you can style it however you like.


Copy this code and paste it in your HTML
  1. function curl($url)
  2. {
  3. $ch = curl_init($url);
  4. curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
  5. curl_setopt($ch,CURLOPT_HEADER, 0);
  6. curl_setopt($ch,CURLOPT_USERAGENT,"www.YOURDOMAIN.com");
  7. curl_setopt($ch,CURLOPT_TIMEOUT,10);
  8. $data = curl_exec($ch);
  9. curl_close($ch);
  10. return $data;
  11. }
  12.  
  13. function GetTwitterFollowerCount($username)
  14. {
  15. $twitter_followers = curl("http://twitter.com/statuses/user_timeline/".$username.".xml?count=1");
  16. $xml = new SimpleXmlElement($twitter_followers, LIBXML_NOCDATA);
  17. return = $xml->status->user->followers_count;
  18. }
  19.  
  20. echo GetTwitterFollowerCount("YourTwitterName");

URL: http://www.nealgrosskopf.com/tech/thread.php?pid=57

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.