Created
March 23, 2013 04:59
-
-
Save spencejs/5226516 to your computer and use it in GitHub Desktop.
Display Latest Tweet From Twitter Without a Plugin
This file contains 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 = "Antinym"; | |
// 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 = "<h2>The Latest on Twitter</h2>"; | |
// 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"; | |
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; | |
} | |
$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