当前位置:首页 » 净水方式 » php过滤html标签

php过滤html标签

发布时间: 2021-03-24 08:25:30

❶ php文件输出如何过滤掉html,代码如下

<b>asasasas</b>这个html标签是加粗标签,如果你想在浏览器上显示的是加粗的asasasas就直接输出
<?php
echo "<b>asasasas</b>";

?>

如果你想输出的<b>asasasas</b>这个字符串的话呢
<?php

echo htmlspecialchars("<b>asasasas</b>");

?>

❷ php如何过滤编辑器的html标签

选择1.将特殊符号进行转换,可以用htmlspecialchars把<变为“<”等
选择2.用正则表达式替换,将标签都删除:
$content=preg_replace('/\<.+?\>/','',$content);

❸ php如何处理html标签

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("/

❹ php mysql查询的时候怎么过滤掉html

你这个问题我之前做项目的时候也遇到过,你可以从数据入库时入手解决,具体做法版就是你可在把数据存入权到数据的时候用strip_tags()函数剥离HTML标签,这样你在查询的时候就不会遇到这种情况了,完全都是数据,如果存入数据库的数据必须要有HTML标记的话那入库的时候可以考虑用htmlspacialchars()函数,希望能够帮到你

❺ php 过滤所有标签中html标签

php的 strip_tags 函数.

❻ php如何过滤html标签,使用什么函数

strip_tags — 从字符串中去除 HTML 和 PHP 标记
语法:
string strip_tags ( string $str [, string $allowable_tags ] )

该函数返回给定的字符串 str 去除空字符、HTML 和 PHP 标记后的结果。
参数:

str 要去除的字符串

allowable_tags 可选参数,指定不被去除的字符列表。

例如:
$str = '<a href="" title="">测试</a>';
echo strip_tags($str);

结果:
测试

❼ 求一个php简单的过滤除<br>,<p>,<style>html标签的正则或方法

针对来你这个<a>123</a>的例子自的

$a=<<<str
<a>123</a>
str;
$preg ="/<(a)>(.*?)<\/(\1)>/is";
$str = preg_replace($preg, "<a>\\2</a>", $a);
echo $str;

除此之外PHP还有一个 过滤标签的函数 你可以看一下手册

❽ 求php 过滤html标签 但不过滤标签里面的文字 的代码

<?php
$str='<ahref="#">href</a>';
//echohtmlspecialchars($str);
echostrip_tags($str);
?>

❾ PHP 过滤HTML中除了img标签外其它所有标签,同时保留标签内容,但<script>标签内的内容都清除。

提供实例:
<?php
$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
echo "\n";
// 允许 <p> 和 <a>
echo strip_tags($text, '<p><a>');
?>
以上例程会输出:专
Test paragraph. Other text
<p>Test paragraph.</p> <a href="#fragment">Other text</a>

具体做法:属
<?php
echo strip_tags($text, 'img');
?>

❿ 用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]*

热点内容
丁度巴拉斯情人电影推荐 发布:2024-08-19 09:13:07 浏览:886
类似深水的露点电影 发布:2024-08-19 09:10:12 浏览:80
《消失的眼角膜》2电影 发布:2024-08-19 08:34:43 浏览:878
私人影院什么电影好看 发布:2024-08-19 08:33:32 浏览:593
干 B 发布:2024-08-19 08:30:21 浏览:910
夜晚看片网站 发布:2024-08-19 08:20:59 浏览:440
台湾男同电影《越界》 发布:2024-08-19 08:04:35 浏览:290
看电影选座位追女孩 发布:2024-08-19 07:54:42 浏览:975
日本a级爱情 发布:2024-08-19 07:30:38 浏览:832
生活中的玛丽类似电影 发布:2024-08-19 07:26:46 浏览:239