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
Post a Comment