PHP Regex to convert text before colon to link -


i need find first occurance of colon ':' , take complete string before , append link.

e.g.

username: @twitter nice site! rt www.google.com : visited! 

needs converted to:

<a href="http://twitter.com/username">username</a>: nice site! rt www.google.com : visited! 

i've got following regex converts string @twitter clickable url:

e.g.

$description = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $description); 

any ideas : )

i'd use string manipulation this, rather regex, using strstr, substr , strlen:

$username = strstr($description, ':', true); $description = '<a href="http://twitter.com/' . $username . '">' . $username . '</a>'              . substr($description, strlen($username)); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -