Home > Backend Development > PHP Tutorial > PHP implementation of deleting non-site external links example code_PHP tutorial

PHP implementation of deleting non-site external links example code_PHP tutorial

WBOY
Release: 2016-07-13 10:24:41
Original
767 people have browsed it

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template