PhP: Display Your Latest Tweet Using PHP
To display your latest Tweet using PHP use this below code:
function latest_tweet($username,$tweetnumber){ $url = "http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=$username&count=10"; $xml = simplexml_load_file($url); $mytweet = $xml->status[$tweetnumber]->text; $firstChar = substr($mytweet, 0, 1); //Exclude @ replies if($firstChar == "@"){ //If this tweet is an @ reply move on to the previous one while ($firstChar == "@"){ $tweetnumber++; $mytweet = $xml->status[$tweetnumber]->text; $firstChar = substr($mytweet, 0, 1); if($firstChar != "@"){ //If the previous tweet is not an @ reply output it $mytweet = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","\\0", $mytweet); return $mytweet; } } }else{ //If first tweet is not an @ reply output it $mytweet = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","\\0", $mytweet); return $mytweet; } } echo latest_tweet('UnchiYeah', 0); ?>