How to get Latest Tweet using php.

Integrating blogs with twitter was a daily routine for me . Thus i decided to write a function that would return you the last tweet of a particular twitter user . It is a simple self explanatory code .

Note : Change $username to your account before you use .

echo "Latest Tweet : ".returnTweet();
function returnTweet()

// Your twitter username.
$username = "xxxxxxxxxxx";

// Prefix - some text you want displayed before your
 latest tweet.

// HTML is OK, but be sure to escape quotes with 
backslashes: for example href=\"link.html\"
$prefix = "";

// Suffix - some text you want display after your
latest tweet. (Same rules as the prefix.)
$suffix = "";

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

$twitterFeed = file_get_contents($feed);

$tweet = parse_feed($twitterFeed);
return $prefix.$tweet.$suffix;


function parse_feed($feed)
$stepOne = explode("<content type=\"html\">", $feed);
$stepTwo = explode("</content>", $stepOne[1]);
$tweet = $stepTwo[0];
$tweet = str_replace("&lt;", "<", $tweet);
$tweet = str_replace("&gt;", ">", $tweet);
return $tweet;
By karuppasamy11486 Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s