Example 1. PHP’s built-in function can remove/delete HTML tags/codes in strings.
strip_tags(string,allow): Function strips HTML, XML and PHP tags.
Parameters: string, required, specifies the string to be checked; allow, optional, specifies the tags that are allowed to exist, and these tags will not be deleted.
Copy code The code is as follows:
$str = 'Guo bowl and pan -PHP';
$str1 = strip_tags($str); / / Keep the tag
echo $str1; // Output Guo bowl and pan - PHP
echo $str2; // The style is different
Example 2, clear certain attribute codes in HTML tag strings
Use PHP to process the HTML code of the article read from the database, and then use regular expressions to match and modify the code. After saving the code, use the static generation function The modified HTML page can be generated.
Because the code we generate is already processed code, it will not affect the loading speed of the HTML page.
The specific [sample code] is as follows:
Copy code The code is as follows:
$ str = "
";
$str = preg_replace('#onclick =([sS]*)"#','',$str);
// Please note that there is a double quotation mark in front of the # symbol, which represents the end of the code
print($str);
? >
http://www.bkjia.com/PHPjc/825086.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825086.htmlTechArticleExample 1. PHP’s built-in function can remove/delete HTML tags/codes in strings. strip_tags(string,allow): Function strips HTML, XML and PHP tags. Parameters: string, required, specified...