方法一,代码如下:
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){
- $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){
- $st=$i;
- }
- if(ord($ss)==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);
|