I'm using a Smarty modifier to turn a plaintext link into a proper hyperlink, I'm using a Smarty modifier for this as it's for a website that utilizes user content, in which only some areas are allowed to have hyperlinks.
This is the modifier:
function smarty_modifier_dolink($text)
{
$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\1:", $text);
$ret = ' ' . $text;
$ret = preg_replace("#(^|[
])([w]+?://[w#$%&~/.-;:=,?@[]+]*)#is", "\1<a href="\2" target="_blank" rel="nofollow">\2</a>", $ret);
$ret = preg_replace("#(^|[
])((www|ftp).[w#$%&~/.-;:=,?@[]+]*)#is", "\1<a href="http://\2" target="_blank" rel="nofollow">\2</a>", $ret);
//$ret = preg_replace("#(^|[
])([a-z0-9&-_.]+?)@([w-]+.([w-.]+.)*[w]+)#i", "\1<a href="mailto:\2@\3">\2@\3</a>", $ret);
$ret = substr($ret, 1);
return $ret;
}
?>
The code for the modifier was shared on another website. It works fine but doesn't work when the plaintext link is in parentheses, any help would be appreciated, thanks!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…