RichardKnox
07-07-2009, 10:15 PM
I wrote a little bit of PHP code for no reason and decided to give it out for free. It's really simple and it all does is grabs your latest tweet using the Twitter Search and then echo's it. This could be used to make something like a status signature or whatever if you just then made the value of $tweet into an image. Anyway, I'm not writing that but if you wish to, enjoy yourself.
<?php
// The function that will do the grabbing of the tweet
function getTweet($url) {
// Get the contents of the ATOM file
$feed = file_get_contents($url);
// Make an XML instance of it
$xml = new SimpleXMLElement($feed);
// Using the XML get the tweet, for this we needed to work out the xml structure
$tweet = $xml->entry->title;
return $tweet;
}
// $username is your twitter username
$username = "cleanString";
// This is the API call URL. &rpp=1 means we will only get the latest status
$url = "http://search.twitter.com/search.atom?q=from:".$username."&rpp=1";
// Use our function we made earlier to grab our latest tweet and echo it
echo getTweet($url);
?>
<?php
// The function that will do the grabbing of the tweet
function getTweet($url) {
// Get the contents of the ATOM file
$feed = file_get_contents($url);
// Make an XML instance of it
$xml = new SimpleXMLElement($feed);
// Using the XML get the tweet, for this we needed to work out the xml structure
$tweet = $xml->entry->title;
return $tweet;
}
// $username is your twitter username
$username = "cleanString";
// This is the API call URL. &rpp=1 means we will only get the latest status
$url = "http://search.twitter.com/search.atom?q=from:".$username."&rpp=1";
// Use our function we made earlier to grab our latest tweet and echo it
echo getTweet($url);
?>