To filter all html tags in a string, you can write a function by yourself and use regular expression filtering. The other method is to use the strip_tags function provided by php. This article describes how to clear html tags from strings in php.
To filter all html tags in a string, you can write a function by yourself and use regular expression filtering. The other method is to use the strip_tags function provided by php.
The code is as follows:
Function clear_html_label ($ html)
{
$ Search = array ("' ] *?>. *? 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 );
}
// Instance application
$ String = 'AAA'
Script fdsafsa ';
Echo clear_html_label ($ string); // aaa fdsafsa
// Use the php built-in function strip_tags (); www.zzarea.com
Echo strip_tags ($ string); // aaa fdsafsa
Conclusion,
The results of the above two functions are exactly the same. one is the user-defined filtering of all html functions, and the other is the php built-in function, but in green, the strip_tags () function of php is used, it must be much higher. At least I won't say much.