欢迎光临 - 我的站长站,本站所有资源仅供学习与参考,禁止用于商业用途或从事违法行为!

php教程

PHP过滤HTML标签代码方法

php教程 我的站长站 2021-09-10 共45人阅读

过滤指定标签大全

$str=preg_replace("/s+/", " ", $str); //过滤多余回车
$str=preg_replace("/<[ ]+/si","<",$str); //过滤<__("<"号后面带空格)
$str=preg_replace("/<!--.*?-->/si","",$str); //注释
$str=preg_replace("/<(!.*?)>/si","",$str); //过滤DOCTYPE
$str=preg_replace("/<(/?html.*?)>/si","",$str); //过滤html标签
$str=preg_replace("/<(/?head.*?)>/si","",$str); //过滤head标签
$str=preg_replace("/<(/?meta.*?)>/si","",$str); //过滤meta标签
$str=preg_replace("/<(/?body.*?)>/si","",$str); //过滤body标签
$str=preg_replace("/<(/?link.*?)>/si","",$str); //过滤link标签
$str=preg_replace("/<(/?form.*?)>/si","",$str); //过滤form标签
$str=preg_replace("/cookie/si","COOKIE",$str); //过滤COOKIE标签
$str=preg_replace("/<(applet.*?)>(.*?)<(/applet.*?)>/si","",$str); //过滤applet标签
$str=preg_replace("/<(/?applet.*?)>/si","",$str); //过滤applet标签
$str=preg_replace("/<(style.*?)>(.*?)<(/style.*?)>/si","",$str); //过滤style标签
$str=preg_replace("/<(/?style.*?)>/si","",$str); //过滤style标签
$str=preg_replace("/<(title.*?)>(.*?)<(/title.*?)>/si","",$str); //过滤title标签
$str=preg_replace("/<(/?title.*?)>/si","",$str); //过滤title标签
$str=preg_replace("/<(object.*?)>(.*?)<(/object.*?)>/si","",$str); //过滤object标签
$str=preg_replace("/<(/?objec.*?)>/si","",$str); //过滤object标签
$str=preg_replace("/<(noframes.*?)>(.*?)<(/noframes.*?)>/si","",$str); //过滤noframes标签
$str=preg_replace("/<(/?noframes.*?)>/si","",$str); //过滤noframes标签
$str=preg_replace("/<(i?frame.*?)>(.*?)<(/i?frame.*?)>/si","",$str); //过滤frame标签
$str=preg_replace("/<(/?i?frame.*?)>/si","",$str); //过滤frame标签
$str=preg_replace("/<(script.*?)>(.*?)<(/script.*?)>/si","",$str); //过滤script标签
$str=preg_replace("/<(/?script.*?)>/si","",$str); //过滤script标签
$str=preg_replace("/javascript/si","Javascript",$str); //过滤script标签
$str=preg_replace("/vbscript/si","Vbscript",$str); //过滤script标签
$str=preg_replace("/on([a-z]+)s*=/si","On1=",$str); //过滤script标签
$str=preg_replace("/&#/si","&#",$str); //过滤script标签,如javAsCript:alert(

清除空格,换行

function DeleteHtml($str)
{
$str = trim($str);
$str = strip_tags($str,"");
$str = ereg_replace("t","",$str);
$str = ereg_replace("rn","",$str);
$str = ereg_replace("r","",$str);
$str = ereg_replace("n","",$str);
$str = ereg_replace(" "," ",$str);
return trim($str);
}

过滤全部HTML

过滤所有HTML标签正则表达式

</?[^>]+>

过滤所有html标签+属性的正则表达式:

$html = preg_replace("/<([a-zA-Z]+)[^>]*>/","<1>",$html);
相关推荐
  • PHP过滤
  • php代码
  • PHP过滤网址https或http代码

    PHP过滤替换我们通常用到“str_replace”语法,下面分享这段代码可以过滤掉网址前面的“http://”,比如:“http://www.wdzzz.com/”替换成:“www.wdzzz.com”$pattern = rtrim(str_replace(&#39;https://&#39;,&#39;&#39;,str_replace(&#39;http://&#39;,...

    php教程 156 2年前
  • PHP过滤HTML标签代码方法

    过滤指定标签大全$str=preg_replace("/\s+/", " ", $str); //过滤多余回车$str=preg_replace("/<[ ]+/si","<",$str); //过滤<__("<"号后面带空格)$str=preg_replace("/<\!--.*?-->/si","",$str); //注释$...

    php教程 45 2年前
  • PHP过滤器方法详解

    什么是PHP过滤器?PHP 过滤器是用于验证和过滤来自非安全来源的数据。测试、验证和过滤用户输入或自定义数据是任何 Web 应用程序的重要组成部分。PHP 的过滤器扩展的设计目的是使数据过滤更轻松快捷。几乎所有的 Web 应用程序都依赖外部的输入。这些...

    php教程 85 3年前
  • 支付宝企业账户转账个人账户php接口代码

    前言支付宝企业账户转账个人账户php接口代码,该接口主要用于平台对用户奖励的发放,场景也很简单就是我在你平台上有余额,我提现,平台给钱。只不过项目中是用的官方的SDK调用的,仔细看了下那个SDK目录,把很多无用的接口(目前自己用不上)也包含在里面,作为强...

    php教程 160 2年前
  • php判断目录文件是否存在

    一段简单的php判断目录文件是否存在代码,收藏记录一下,以后肯定用得到的。<?php$filename = &#39;../../e/install/&#39;; if (file_exists($filename)) { echo "<h3><div align=&#39;center&#39;><font color=&#39;#FF0000&#39;>存在安全风险!请将 ...

    php教程 115 2年前
  • curl函数获取API接口数据方法

    PHP利用curl函数,获取API接口数据方法示例代码,自用收藏<?php $weather = curl_init(); curl_setopt($weather,CURLOPT_URL,"https://api.pc2801.com/cqssc/".time()); curl_setopt($weather, CURLOPT_SSL_VERIFYPEER, false); //如果...

    php教程 89 2年前
  • 158网盘直连解析代码

    API代码<?php/*** @package 158Pan* @author Andy* @version 1.2.0* @link https://lsland.cn*/// 指定允许其他域名访问 header(&#39;Access-Control-Allow-Origin:*&#39;);header(&#39;content-type:application/json;charset:utf-8&#39;);functi...

    php教程 132 2年前
  • PHP获取QQ用户昵称+头像API接口代码

    如果要获得QQ用户的头像和昵称,需要在腾讯开放平台申请API接入才可以,但是这个不需要!只需要输入用户的正确的QQ号即可返回用户的头像和昵称。API接口代码<?php // 通过QQ号即可获取用户信息 // 获取QQ头像接口// http://q1.qlogo.cn/g?b=qq&nk=QQ号&s=...

    php教程 224 2年前