Found this gorgeous function to get the last Twitter Update from a user.
Features
- It prints the links inside the tweets.
- Also puts a link on a @user reply tweets
Code
function getTwitterStatus($userid,$x){
$url = "http://twitter.com/statuses/user_timeline/$userid.xml?count=$x";
$xml = simplexml_load_file($url) or die('could not connect');
echo '<ul>';
foreach($xml->status as $status){
$text = twitterify( $status->text );
echo '<li>'.utf8_decode($text).'</li>';
}
echo '</ul>';
}
function twitterify($ret) {
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" >\\2", $ret);
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" >\\2", $ret);
$ret = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" >@\\1</a>", $ret);
$ret = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" >#\\1</a>", $ret);
return $ret;
}
// Now let's print the Tweets.
// Put your own username.
// Set the number of tweets.
print_r(getTwitterStatus('quicoto_dev', 1));
Code language: PHP (php)
I had some codification problems. I added the iconv function in the return:
return iconv("ISO-8859-1", "UTF-8", $ret);
Nice trick, adding it to delicious.
Glad you like it 😉