Function code used by php to filter html tags. Php function code for filtering html tags this article provides four function codes for filtering html tags using php, method 1 uses the strip_tags function provided by php to filter all html tags. function code used by php to filter html tags. This article provides four function codes used by php to filter html tags, method 1 uses the strip_tags function of php to filter all html tags. Method 2 uses regular expressions to filter html tags, the third method is to clear the user-defined function of the HTML tag, and determine whether it is a letter based on the ascii code value before filtering.
Function code for filtering html tags in the php Tutorial
This article provides four function codes that use php to filter html tags. Method 1 uses the strip_tags function of php to filter all html tags, method 2 uses regular expressions to filter html tags. Method 3 is the user-defined function used to clear html tags. the user-defined function checks whether the tags are letters based on the ascii encoding value before filtering.
*/
// The most direct html filtering method
Strip_tags ();
// Method 2 use regular expression filtering
Function _ filter ($ string ){
Return str_replace (array ("n", "rn", "r", ''), array ('
','
','
', ''), Strip_tags ($ string ,'
'));
}
// Regular expression 2
Preg_replace ('/(
) {1,}/is ','
', $ Str );
// Regular expression 3
Function delhtml ($ str) {// clear html tags
$ St =-1; // start
$ Et =-1; // end
$ 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;
}
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;
}
//
$ Str ='
Www.bkjia.com />
';
$ Reg = '/( | ) | <. +?> /I ';
Echo preg_replace ($ reg, '$ 1', $ str );
Http://www.bkjia.com/PHPjc/445430.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445430.htmlTechArticlephp filter html tag function code this article provides four use php filter html tag function code, method 1 uses the strip_tags function of php to filter all html tags...