In php, there are many HTML tag methods to remove strings. The most common method is to use the strip_tags function together to retain only characters, the regular expression is also used in addition to selective removal. example 1: php built-in functions can be removed... in php, there are many HTML tag methods to remove strings. The most common method is to use the strip_tags function together to retain only characters, the regular expression is also used in addition to selective removal.
Example 1: Php built-in functions can remove/delete HTML tags/codes in strings:
Strip_tags (string, allow): The function removes HTML, XML, and PHP labels.
Parameters: String, required. it specifies the string to be checked, allow, optional. it specifies the tags that are allowed. these tags 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 the tag echo $ str1; // output the Guo bowl Basin-PHP echo $ str2; // The style is different.
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 the HTML page will not be affected. the specific code is as follows:
Related regular expressions: match any content: [sS] *.
Article link:
Save this article for favorites!