Home > Backend Development > PHP Tutorial > How to filter other website links in html in php (domain name whitelist function)_PHP tutorial

How to filter other website links in html in php (domain name whitelist function)_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:31:53
Original
1233 people have browsed it

复制代码 代码如下:

/**

* Filter external links
* @param array $local_domain Domain name array of this site
* @param string $message Text content
*/
    function replace_outer_links($local_domain_arr, $message) {

        $pattern= '/<[^>]*href=['"]http[s]?://(?!' ;
        $i = 0 ;
        foreach ($local_domain_arr as $local_domain){
            if($i==0){
                 $pattern .= 'www.' .$local_domain.'|'.$local_domain.'|[w_]+.'.$local_domain ;
            }else{
                 $pattern .= '|www.' .$local_domain.'|'.$local_domain.'|[w_]+.'.$local_domain ;
            }
             $i++ ;
        }
        $pattern .=')[^'^"]*['"][^>]*>(.+?)/is';  
        return preg_replace($pattern,'$1',$message);
    }

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/760287.htmlTechArticle复制代码 代码如下: /*** Filter external site links * @param array $local_domain Domain name array of this site * @param string $message text content*/ function replace_outer_links($local_do...
Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template