Generally when building a website system, due to factors such as optimization, it is necessary to delete links that are not on this site when adding articles. For this requirement, PHP can be used to process the article content to achieve external links to the article. The effect of automatic deletion.
This example code mainly refers to the external link deletion method of Dreamweaver CMS content management system.
Copy code The code is as follows:
/**
* Delete non-site links
*
* @access public
* @param string $body content
* @param array $allow_urls Allowed hyperlinks
* @return string
*/
function Replace_Links( &$body, $allow_urls= array() )
{
$host_rule = join('|', $allow_urls);
$host_rule = preg_replace("#[nr]#", '', $host_rule);
$host_rule = str_replace('.', "\.", $host_rule);
$host_rule = str_replace('/', "\/", $host_rule);
$arr = '';
preg_match_all("#
]*)>(.*)#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; y($rparr) )
, body;
}
http://www.bkjia.com/PHPjc/825360.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/825360.html
TechArticle
Generally when building a website system, it is not necessary to delete articles when adding them due to optimization and other factors. For links to this site, you can ask PHP to handle this requirement within the article...