In php, there are many HTML Tag methods to remove strings. The most common method is to use the strip_tags function together to keep only characters, the regular expression is also used in addition to selective removal. below
In php, there are many HTML Tag methods to remove strings. The most common method is to use the strip_tags function together to keep only characters, the regular expression is also used in addition to selective removal. below
Example 1: php built-in functions can remove/delete HTML tags/codes from strings.
Strip_tags (string, allow): The function removes HTML, XML, and PHP labels.
Parameter: string, required. It specifies the string to be checked; allow, optional. It specifies the tags that are allowed and will not be deleted.
The Code is as follows:
$ Str = 'Guo bowl basin-php ';
$ Str1 = strip_tags ($ str); // delete all HTML tags
$ Str2 = strip_tags ($ str, ''); // keep tags
Echo $ str1; // output Guo bowl basin-PHP
Echo $ str2; // different styles
Example 2: Clear some attribute codes in the HTML Tag string
Use PHP to process the HTML code of the document read from the database, and then use regular expressions to match and modify the code. Save the code and use the static generation function to generate the modified HTML page.
Because the generated code is already processed, the loading speed of HTML pages will not be affected.
The [Sample Code] is as follows:
The Code is as follows:
$ Str = "";
$ Str = preg_replace ('# onclick = ([sS] *) "#','', $ str );
// # Note that there is a double quotation mark before the symbol, indicating the end code
Print ($ str );
?>