php htmlfilter,php 过滤所有html标签

首先我们推荐filter_sanitize_string ,filter_sanitize_string 过滤器去除或编码不需要的字符。

这个过滤器删除那些对应用程序有潜在危害的数据。它用于去除标签以及删除或编码不需要的字符。

name: "string"

id-number: 513

可能的选项或标志:

filter_flag_no_encode_quotes - 该标志不编码引号

filter_flag_strip_low - 去除 ascii 值在 32 以下的字符

filter_flag_strip_high - 去除 ascii 值在 32 以上的字符

filter_flag_encode_low - 编码 ascii 值在 32 以下的字符

filter_flag_encode_high - 编码 ascii 值在 32 以上的字符

filter_flag_encode_amp - 把 & 字符编码为 &

*/

$var="bill gates";

var_dump(filter_var($var, filter_sanitize_string));

/*

第二个函数strip_tags

strip_tags() 函数剥去 html、xml 以及 php教程 的标签。

语法

strip_tags(string,allow)

*/

echo strip_tags("hello world!");

//hello world!

function uh($str)

{

$farr = array(

"/s+/",

//过滤多余的空白

"/]*?)>/isu",

//过滤

以加入

"/(]*)on[a-za-z]+s*=([^>]*>)/isu",

//过滤网页特效的on事件

);

$tarr = array(

" ",

"<123>", //如果要直接清除不安全的标签,这里可以留空

"12",

);

$str = preg_replace( $farr,$tarr,$str);

return $str;

}

更多详细内容请查看:http://www.bKjia.c0m/phper/19/70dd2a905e74cefc9be9c0f17268dadc.htm

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值