tutorials

I'm a site optimization freak and displaying my latest tweets with the usual code snippet was adding an other javascript to my website, so I searched for an other way of doing it, sans JavaScript. There were probably WordPress plugins for this but I hate having to install too much plugins. The first Google results do the job just fine... for english speakers. If you have special characters or accents, some PHP code won't show them properly.

I have found the solution on NickHeer.com ! Go to this page to get the code to display your latest tweets very simple with PHP or grab it here :

<?php
$username = "your username";
$feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1";
function parse_feed($feed) {
$stepOne = explode("<content type=\"html\">", $feed);
$stepTwo = explode("</content>", $stepOne[1]);
$tweet = $stepTwo[0];
$tweet = htmlspecialchars_decode($tweet,ENT_QUOTES);
return $tweet;
}
$twitterFeed = file_get_contents($feed);
echo('&quot;'.parse_feed($twitterFeed).'&quot;');
?>

You just have to edit your username on line 2 before using it !

Share and Enjoy:
  • Twitter
  • Tumblr
  • Facebook
  • del.icio.us
  • Design Float
  • Digg
  • Netvibes
  • Mixx
  • Google Bookmarks
  • Yahoo! Bookmarks
  • NewsVine
  • Posterous
  • StumbleUpon
  • Technorati
  • Reddit

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>