Codesnipp.it Social Code Sharing

stephen coe

linkify tweets

by stephen coe on Feb 12, 2012

function linkify($text){ //links $text = preg_replace( '@(https?://([-\w\.]+)+(/([\w/_\.]*(\?\S+)?(#\S+)?)?)?)@', '<a href="$1" title="" target="_blank">$1</a>', $text); //hashtag $text = preg_replace( '/\s+#(\w+)/', ' <a href="http://search.twitter.com/search?q=%23$1" title="Search on twitter for #$1" target="_blank">#$1</a>', $text); //users $text = preg_replace( '/@(\w+)/', '<a href="http://twitter.com/$1" title="$1 on twitter" target="_blank">@$1</a>', $text); return $text; }

Can't see the comments? Please login first :)