/**
* Delete Non-site links
*
* @access Public
* @param string $body content
* @param array $allow _urls allow hyperlinks
* @return String
*/
Function Replace_links (& $body, $allow _urls=array ())
{
$host _rule = Join (' | ', $allow _urls);
$host _rule = preg_replace ("#[\n\r]#", "", $host _rule);
$host _rule = Str_replace ('. ', "\ \", $host _rule);
$host _rule = str_replace ('/', "\\/", $host _rule);
$arr = ";
Preg_match_all ("#<a ([^>]*) > (. *) <\/a> #iU", $body, $arr);
if (Is_array ($arr [0]))
{
$rparr = Array ();
$tgarr = Array ();
foreach ($arr [0] as $i = $v)
{
if ($host _rule! = "&& preg_match (' # '. $host _rule. ' #i ', $arr [1][$i])
{
Continue
} else {
$rparr [] = $v;
$tgarr [] = $arr [2][$i];
}
}
if (!empty ($rparr))
{
$body = Str_replace ($rparr, $tgarr, $body);
}
}
$arr = $rparr = $tgarr = ";
return $body;
}
PHP implementation to remove non-site external link Instance code