Posts tagged ‘latest tweet’


Display your latest Tweet in PHP

So on my mobile site ( I created a button to link to my Twitter and this very blog you are reading. This got me thinking what I could do to keep the content fresh without much effort. As the mobile site only consists of a couple of lines of text anyway, I thought a “Latest Tweet” section would be good – because it would be ever-changing. After a bit of googling I tweaked a few bits of PHP I found to come up with the following:

$username = "cytedesign";
$feed = "" . $username . "&rpp=1";

function parse_feed($feed) {
    $stepOne = explode("", $feed);
    $stepTwo = explode("", $stepOne[1]);
    $tweet = $stepTwo[0];
	$tweet = htmlspecialchars_decode($tweet,ENT_QUOTES);
    return $tweet;

$twitterFeed = file_get_contents($feed);

I was so pleased with this in fact that I will use it on the full version of the site as well, and file it away for my employers’ website when we start company Tweeting.

Tags: ,