Home > Backend Development > PHP Tutorial > Code to clear HTML tags in strings under PHP_PHP Tutorial

Code to clear HTML tags in strings under PHP_PHP Tutorial

WBOY
Release: 2016-07-21 15:34:30
Original
795 people have browsed it

This article introduces php to clear the html tags in the string
There are two methods to filter all html tags in the string. One is to write a function ourselves and use regular filtering, and the other is to use php's own function strip_tags.

Copy code The code is as follows:

function clear_html_label($html)
{
$search = array ("']*?>.*?'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);
}

//Example application

$string ='aaa
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template