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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-19 我要评论
想了解php过滤html中的其他网站链接的方法(域名白名单功能)的相关内容吗,在本文为您仔细讲解php过滤html的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:php过滤html,下面大家一起来学习吧。

复制代码 代码如下:

/**

     * 过滤外站链接
     * @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 .=')[^\'^\"]*[\'\"][^>]*>(.+?)<\/a>/is';  
        return preg_replace($pattern,'$1',$message);
    }

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们