Here’s a quick piece of code to highlight replies to users in twitter for example @ashleyford this script uses regular expression to find and replace a based on two things. Firstly it checks for a space before the @ symbol and then checks for the space at the end of the users name, it then takes that string and replaces it with a link to the user twitter profile. Useful if you have a dynamic list of tweets that you want to linkify. All you need to do is change $ret to the variable the contains your string.
$ret = preg_replace("#(^|[n ])@([^ "tnr<]*)#ise", "'\1@\2'", $ret);
These two lines of code do a similar job with regards the structure however they look for the http:// and www.Â to determine a link.
$ret = preg_replace("#(^|[n ])([w]+?://[w]+[^ "nrt<]*)#ise", "'\1\2'", $ret);
$ret = preg_replace("#(^|[n ])((www|ftp).[^ "tnr<]*)#ise", "'\1\2'", $ret);