本文章收藏了多种关于php教程 过滤html标签方法的方法,有利用php自带函数过滤html标签也有使用用户自定义函数加正则表达式来过滤htm标签,好了下面我们先看二款最简单的方法吧。
方法一
echo strip_tags("hello world!");
strip_tags --- 去除字串中的html和php标签
语法 : string strip_tags (string str [, string allowable_tags])
说明 :
此函式试着从给予的字串中去除所有html和php标签,如果是不完整或是假的标签时则会有错误,它和fgetss( )使用相同的方法去除标签。
$reg = '/(?p>|)|<.>/i';
echo preg_replace($reg,'$1',$str);
?>
过滤方法二
function delhtml($str){ //清除html标签
$st=-1; //开始
$et=-1; //结束
$stmp=array();
$stmp[]=" ";
$len=strlen($str);
for($i=0;$i $ss=substr($str,$i,1);
if(ord($ss)==60){ //ord(" $st=$i;
}
if(ord($ss)==62){ //ord(">")==62
$et=$i;
if($st!=-1){
$stmp[]=substr($str,$st,$et-$st+1);
}
}
}
$str=str_replace($stmp,"",$str);
return $str;
}
过滤方法三
function clear_html_label($html)
{
$search = array ("'<script>]*?>.*?</script>'si", "']*?>'si", "'([rn])[s]+'", "'&(quot|#34);'i", "'&(amp|#38);'i", "'&(lt|#60);'i", "'&(gt|#62);'i", "'&(nbsp|#160);'i", "'&(iexcl|#161);'i", "'&(cent|#162);'i", "'&(pound|#163);'i", "'&(copy|#169);'i", "'(d+);'e");
$replace = array ("", "", "1", """, "&", "", " ", chr(161), chr(162), chr(163), chr(169), "chr(1)");return preg_replace($search, $replace, $html);
}
//实例应用
$string ='aaa
<script>fdsafsa'; <br />
echo clear_html_label($string);//aaa fdsafsa</script>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use