Skip to content

Instantly share code, notes, and snippets.

@michaelaguiar
Created October 8, 2011 21:44
Show Gist options
  • Select an option

  • Save michaelaguiar/1272924 to your computer and use it in GitHub Desktop.

Select an option

Save michaelaguiar/1272924 to your computer and use it in GitHub Desktop.
PHP - Display most recent twitter post
<?php
// Your twitter username.
$username = "twitter user name";
// Prefix - Display something before the tweet
$prefix = "";
// Suffix - Display something after the tweet
$suffix = "";
$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 = str_replace("&lt;", "<", $tweet);
$tweet = str_replace("&gt;", ">", $tweet);
return $tweet;
}
function get_profile_image($username, $size = '') {
return 'http://api.twitter.com/1/users/profile_image/'.$username.'.json?size='.$size;
}
// Image Sizes: original, reasonably_small, bigger, normal, mini,
echo '<img src="'.get_profile_image($username, 'normal').'" />';
$twitterFeed = file_get_contents($feed);
echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment