Home > Backend Development > PHP Tutorial > php过滤html中的其他网站链接的方法(域名白名单功能)_PHP

php过滤html中的其他网站链接的方法(域名白名单功能)_PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 11:54:55
Original
883 people have browsed it

复制代码 代码如下:
/**

     * 过滤外站链接
     * @param array $local_domain  本站域名 数组
     * @param string $message    文本内容
     */
    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);
    }

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
html form data cannot be submitted to php
From 1970-01-01 08:00:00
0
0
0
How to convert html to PHP?
From 1970-01-01 08:00:00
0
0
0
How to connect php files with HTML
From 1970-01-01 08:00:00
0
0
0
How to embed php in HTML attribute?
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