㈠ 用php过滤html部分标签
$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","On\\1=",$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("\r\n","",$str);
$str = ereg_replace("\r","",$str);
$str = ereg_replace("\n","",$str);
$str = ereg_replace(" "," ",$str);
return trim($str);
}
过滤HTML属性
1,过滤所有html标签的正则表达式:
复制代码 代码如下:
</?[^>]+>
//过滤所有html标签的属性的正则表达式:
$html = preg_replace("/<([a-zA-Z]+)[^>]*>/","<\\1>",$html);
3,过滤部分html标签的正则表达式的排除式(比如排除<p>,即不过滤<p>):
复制代码 代码如下:
</?[^pP/>]+>
4,过滤部分html标签的正则表达式的枚举式(比如需要过滤<a><p><b>等):
复制代码 代码如下:
</?[aApPbB][^>]*>
5,过滤部分html标签的属性的正则表达式的排除式(比如排除alt属性,即不过滤alt属性):
复制代码 代码如下:
\s(?!alt)[a-zA-Z]+=[^\s]*
6,过滤部分html标签的属性的正则表达式的枚举式(比如alt属性):
复制代码 代码如下:
(\s)alt=[^\s]*
㈡ php 正则过滤掉 指定的a标签
我这个更好
<?php
$str='<a class="qc" href="/car">汽车</a><a class="db" href="/car">大巴</a><a class="qc" href="/car">汽车</a>';
$str=preg_replace("/<a class=\"qc\" href=\"(.*)\">(.*)<\\/a>/iU","$2",$str); //过滤script标签
echo $str;
?>
㈢ php正则匹配所有a标签,并删除
1,过滤所有html标签的正则表达式:</?[^>]+>
2,过滤所有html标签的属性的正则表达式:$html = preg_replace("/<([a-zA-Z]+)[^>]*>/","<\\1>",$html);
3,过滤部分html标签的正则表达式的排除式(比如排除<p>,即不过滤<p>):</?[^pP/>]+>
4,过滤部分html标签的正则表达式的枚举式(比如需要过滤<a><p><b>等):</?[aApPbB][^>]*>
5,过滤部分html标签的属性的正则表达式的排除式(比如排除alt属性,即不过滤alt属性):\s(?!alt)[a-zA-Z]+=[^\s]*
㈣ php怎么过滤
使用单独一个模块,这个模块负责所有的安全处理。
这个模块被包含在所有公开的 PHP 脚本的最前端(或者非常靠前的部分)。
参考下面的脚本security.inc
<?php
switch($_POST['form'])
{
case'login':
$allowed=array();
$allowed[]='form';
$allowed[]='username';
$allowed[]='password';
$sent=array_keys($_POST);
if($allowed==$sent)
{
include'/inc/logic/process.inc';
}
break;
}
?>
㈤ php 过滤掉html标签及标签内的所有内容
方法一:使用strip_tags()函数
strip_tags() 函数剥去字符串中的 HTML、XML 以及PHP的标签。
使用案例:
$string = "<p>这里是潘旭博客</p>"
$newStr = strip_tags($string);
echo $newStr;
方法二:使用str_replace()函数
str_replace() 函数以其他字符替换字符串中的一些字符(区分大小写)
使用案例:
$string = "<p>这里是潘旭博客</p>";
$newStr = str_replace(array("<p>","</p>"),array("",""));
echo $newStr;
另外还有一种是通过正则的方法,请参考:https://panxu.net/article/8385.html
㈥ php正则表达式去除A标签求解答
不用去, 你是不是不想让 这段html解析?
很简单 , 你这么写就行:
$str = htmlspecialchars('<a href="www..com" target="_blank" class="keylink">玉石</a>');
echo $str;
你看看最终的$str 是不是不会被解析了, 原理的话你查看下网页源码你就一目了然了.
㈦ php 用正则表达式,去除A标签
stringstrip_tags ( string$str [, string$allowable_tags ] )
从字符串中去除 HTML 和 PHP 标记
㈧ php正则表达式去掉开头的a标签
$res = preg_replace("/<a.+<\/a>(.*)/", "$1", $a);
$res就是你要的结果
㈨ php 正则 匹配所有有a标签的一段文字 全部去除
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class test
{
public static void main(String[] args) throws IOException
{
System.out.print("输入圆盘的个数:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int m=Integer.parseInt(str);
System.out.println("移动步骤:");
hanoi(m,'A','B','C');
}
㈩ PHP过滤html,把html代码中的a标签的target属性由_blank改为 _self ,如何才能实现
$string 整个页面的代码
str_replace("_blank","_self ",$string)