We learn everyday. I came across this script and though i am new to regex would like to know if it’s a safe script to use and what it does actually.
From I assume it removes clickable links in an a text but would ilke to know more.
function new_regex($text = '')
{
$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
$ret = ' ' . $text;
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
$ret = substr($ret, 1);
return $ret;
}
The first line does surprisingly little. It looks for active scripting uri prefixes, but replaces them with themselves. That seems a misguided attempt at security something.
The three following preg_replace calls replace
http://URLs or justwww.*domain names andxyz@emailaddresses. But it does not remove them, it replaces them with clickable HTML links.