PHP Filter function code for HTML tags this article provides four of PHP filtering HTML tag function code, one of the simplest use of PHP's own function strip_tags to filter all HTML tags, method two using regular expressions to filter the HTML tags, The third method is to clear the HTML tags of the user-defined function, according to the ASCII encoding value to determine whether to filter the letter.
PHP Tutorial Filter function code for HTML tags
This article provides four of PHP filtering HTML tags using the function code, one of the simplest use of PHP's own function strip_tags to filter all HTML tags, method two use regular expressions to filter HTML tags, method Three is to clear the HTML tag user-defined function, Determines whether the letter is re-filtered according to the ASCII encoded value.
*/
The most straightforward way to filter HTML
Strip_tags ();
Method two using regular filter
function _filter ($string) {
return Str_replace (Array ("n", "RN", "R", ""), Array ('
','
','
', '), Strip_tags ($string, '
'));
}
Regular two
preg_replace ('/(
) {1,}/is ', '
', $STR);
Regular three
function delhtml ($STR) {//Clear HTML tags
$st =-1; Begin
$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 <> < a=""> />
';
$reg = '/( | ) |<.+?>/i ';
Echo preg_replace ($reg, ' $ ', $str); <>
http://www.bkjia.com/PHPjc/445430.html www.bkjia.com true http://www.bkjia.com/PHPjc/445430.html techarticle PHP Filter function code for HTML tags this article provides four code to filter HTML tags using PHP, the simplest way to use PHP's own function strip_tags to filter all HTML tags ...