记住用户名密码
I. strip_tags
strip_tags($str) 去掉 HTML 及 PHP 的标记
语法: string strip_tags(string str);
传回值: 字串
函式种类: 资料处理
内容说明 :
解析:本函式可去掉字串中包含的任何 HTML 及 PHP 的标记字串。若是字串的 HTML 及 PHP 标签原来就有错,例如少了大于的符号,则也会传回错误。这个函数和 fgetss() 有着相同的功能
例子
echo strip_tags("Hello world!"); # Hello world!
II. htmlspecialchars
这个函数把html中的标签转换为html实体,博客的代码展示就必须使用这个函数,要不贴出来的代码就会被执行了。
预定义的字符是:
& (和号) 成为 &
” (双引号) 成为 ”
‘ (单引号) 成为 ‘
< (小于) 成为 < > (大于) 成为 >
例子
$new = htmlspecialchars("Test", ENT_QUOTES); echo $new; # <a href='test'>Test</a> # 如果需要展现 ,那么浏览器解析HTML的时候会自动将他变为换行 # 但是通过htmlspecialchars就可以让< 变为 '
与htmlspecialchars功能相反的函数是htmlspecialchars_decode,他会把HTML实体转化为字符!
$descclear = str_replace("\r","",$descclear);//过滤换行 $descclear = str_replace("\n","",$descclear);//过滤换行 $descclear = str_replace("\t","",$descclear);//过滤换行 $descclear = str_replace("\r\n","",$descclear);//过滤换行 $descclear = preg_replace("/\s+/", " ", $descclear);//过滤多余回车 $descclear = preg_replace("/<[ ]+/si","<",$descclear); //过滤<__("<"号后面带空格) $descclear = preg_replace("/<\!--.*?-->/si","",$descclear); //过滤html注释 $descclear = preg_replace("/<(\!.*?)>/si","",$descclear); //过滤DOCTYPE $descclear = preg_replace("/<(\/?html.*?)>/si","",$descclear); //过滤html标签 $descclear = preg_replace("/<(\/?head.*?)>/si","",$descclear); //过滤head标签 $descclear = preg_replace("/<(\/?meta.*?)>/si","",$descclear); //过滤meta标签 $descclear = preg_replace("/<(\/?body.*?)>/si","",$descclear); //过滤body标签 $descclear = preg_replace("/<(\/?link.*?)>/si","",$descclear); //过滤link标签 $descclear = preg_replace("/<(\/?form.*?)>/si","",$descclear); //过滤form标签 $descclear = preg_replace("/cookie/si","COOKIE",$descclear); //过滤COOKIE标签 $descclear = preg_replace("/<(applet.*?)>(.*?)<(\/applet.*?)>/si","",$descclear); //过滤applet标签 $descclear = preg_replace("/<(\/?applet.*?)>/si","",$descclear); //过滤applet标签 $descclear = preg_replace("/<(style.*?)>(.*?)<(\/style.*?)>/si","",$descclear); //过滤style标签 $descclear = preg_replace("/<(\/?style.*?)>/si","",$descclear); //过滤style标签 $descclear = preg_replace("/<(title.*?)>(.*?)<(\/title.*?)>/si","",$descclear); //过滤title标签 $descclear = preg_replace("/<(\/?title.*?)>/si","",$descclear); //过滤title标签 $descclear = preg_replace("/<(object.*?)>(.*?)<(\/object.*?)>/si","",$descclear); //过滤object标签 $descclear = preg_replace("/<(\/?objec.*?)>/si","",$descclear); //过滤object标签 $descclear = preg_replace("/<(noframes.*?)>(.*?)<(\/noframes.*?)>/si","",$descclear); //过滤noframes标签 $descclear = preg_replace("/<(\/?noframes.*?)>/si","",$descclear); //过滤noframes标签 $descclear = preg_replace("/<(i?frame.*?)>(.*?)<(\/i?frame.*?)>/si","",$descclear); //过滤frame标签 $descclear = preg_replace("/<(\/?i?frame.*?)>/si","",$descclear); //过滤frame标签 $descclear = preg_replace("/<(script.*?)>(.*?)<(\/script.*?)>/si","",$descclear); //过滤script标签 $descclear = preg_replace("/<(\/?script.*?)>/si","",$descclear); //过滤script标签 $descclear = preg_replace("/javascript/si","Javascript",$descclear); //过滤script标签 $descclear = preg_replace("/vbscript/si","Vbscript",$descclear); //过滤script标签 $descclear = preg_replace("/on([a-z]+)\s*=/si","On\\1=",$descclear); //过滤script标签 $descclear = preg_replace("/
目前有 0 条留言 其中:访客:0 条, 博主:0 条