Created
October 8, 2011 21:44
-
-
Save michaelaguiar/1272924 to your computer and use it in GitHub Desktop.
PHP - Display most recent twitter post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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("<", "<", $tweet); | |
| $tweet = str_replace(">", ">", $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