PHP deletes the code of an instance that does not link to the internal and external sites. Generally, when creating a website system, you need to delete a link that is not on this site when adding an article due to optimization or other factors, for this requirement, you can let PHP handle the website system in the next article, and delete the link not on this site when you need to add the article for optimization and other factors, for this requirement, PHP can process the content of the article to achieve the automatic deletion of the article's external links.
This example code mainly refers to the method for deleting external links in the CMS content management system.
The code is as follows:
/**
* Delete a non-site link
*
* @ Access public
* @ Param string $ body content
* @ Param array $ hyperlinks allowed by allow_urls
* @ 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> # 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;
}
...