In the archives, there’s a post that shows you how to show your latest tweet on your website using jQuery. While that method was OK, I found it rather temperamental. I have a PHP solution, which seems to be more responsive. The code is nice and easy, and will allow you to have something like this on your website:
Note: the graphics/styling obviously won’t appear, just the Tweet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <?php function parse_feed($feed) { $stepOne = explode("<content type=\"html\">", $feed); $stepTwo = explode("</content>", $stepOne[1]); $tweet = $stepTwo[0]; $tweet = html_entity_decode($tweet); return $tweet; } function showTwitter($username) { $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1"; $twitterFeed = file_get_contents($feed); return stripslashes(parse_feed($twitterFeed)); } ?> |
And to print the Tweet, you just need to pass your Twitter username into the following function:
1 | <?php echo showTwitter("YourTwitterUsername");?> |
0 comments:
Post a Comment