Fetch twitter updates via PHP
Want to display your (or maybe be someone else’s) public timeline using php? Ok, here’s the solution for it:
<?php
$username = “amanjain”;
$rssUrl = “http://twitter.com/statuses/user_timeline/$username.rss”;
$rss = @file_get_contents($rssUrl);
if($rss)
{
$xml = @simplexml_load_string($rss);
if($xml !== false)
{
foreach($xml->channel->item as $tweet)
{
echo $tweet->pubDate.”\n”;
echo substr($tweet->description,10).”\n\n”;
}
}
else
{
echo “Error: RSS file not valid!”;
}
}
else
{
echo “Error: RSS file not found, dude. Username invalid or requires authentication”;
}
?>
Find the script live here: http://blog.amanjain.com/twitter

