方法一,代码如下:
echo strip_tags("hello <b>world!</b>");
strip_tags --- 去除字串中的html和php标签
语法:string strip_tags (string str [, string allowable_tags])
说明:此函式试着从给予的字串中去除所有html和php标签,如果是不完整或是假的标签时则会有错误,它和fgetss( )使用相同的方法去除标签,代码如下:
$reg = '/(</?p>|<brs*/?>)|<.+?>/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<$len;$i++){ $ss=substr($str,$i,1); if(ord($ss)==60){ //ord("<")==60 $st=$i;//开源代码phprm.com } 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<br /> <script>fdsafsa'; echo clear_html_label($string);//aaa fdsafsa

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

Zend Studio 13.0.1
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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.
