You’ll probably have noticed if you’re using the Twitter API that when you get the text of the tweet you don’t get any of the @usernames or #hashtags, or even URLs converted to actual links. It doesn’t look like a lot of the libraries (for PHP at least) bother with doing that either.
Here’s the code to get it to do that though:
<?php
$twitter_user = "shamess";
$json = file_get_contents ("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=".$twitter_user."&count=3&trim_user=true");
$tweets = json_decode ($json);
foreach ($tweets as $tweet) {
// change all the urls to links
$tweet_text = preg_replace ("/http://(S+)/i", "<a href="http://$1">http://$1</a>", $tweet->text);
// @usernames
$tweet_text = preg_replace ("/@(w+)/", "<a href="http://twitter.com/$1">@$1</a>", $tweet_text);
// #hashtags too
$tweet_text = preg_replace ("/#(w+)/", "<a href="http://twitter.com/search?q=$1">#$1</a>", $tweet_text);
echo "<li>".$tweet_text." - <em><a href="http://twitter.com/shamess/status/".$tweet->id_str."">".date ('l at H:i', strtotime ($tweet->created_at))."</a></em></li>n";
}