Gerando hyperlinks do Twitter em string no PHP

Esta simples função acrescenta hyperlinks em HTML nos status do Twitter, que são puxados via API.

Função

function addTwitterLink ($string){
	$string = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $string);
	$string = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"https://\\2\" target=\"_blank\">\\2</a>", $string);
	$string = preg_replace("/@(\w+)/", "<a href=\"https://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $string);
	$string = preg_replace("/#(\w+)/", "<a href=\"https://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $string);
	print $string;
}

Utilização

addTwitterLink ('Bom dia do @comfaa a todos os meus followers! #show');