Friday, August 13, 2010

Display My Latest Tweet in My Web Page

<?
echo "Latest Tweet : ".returnTweet();
function returnTweet()
{

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

// Prefix - some text you want displayed before yourlatest 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 = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1";

$twitterFeed = file_get_contents($feed);

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

}

function parse_feed($feed)
{
$stepOne = explode("", $feed);
$stepTwo = explode("
", $stepOne[1]);
$tweet = $stepTwo[0];
$tweet = str_replace("&l t;", "<", $tweet);
$tweet = str_replace("&g t;", ">", $tweet);
return $tweet;
}
?>

No comments:

Post a Comment