Saturday, April 17, 2010

PHP script for getting tweet updates

Here is the php script to get updates from a twitter account.

   $uname = "YourUserName";
   $url = "http://twitter.com/statuses/user_timeline/$uname.rss";
   $rss = @file_get_contents($url);

  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";
                   }
            }
           else
             {
                   echo "Error: RSS file not valid!";
             }
       }
       else
      {
          echo "Error: RSS file not found, Invalid username";
      }
?>