What is the definition and usage of the PHP strip_tags () function?
Many novice friends learn PHP, sometimes encounter some small problems, such as how to remove the string in the label, string garbled problem, in fact, these problems are very simple, the general garbled problem is the character encoding is not set, as long as the character encoding is set, basically will not appear garbled problem, Specific article can refer to this article PHP Chinese garbled Problem solution Summary, then how to remove the string label it? Actually removes the string the label is also very simple, only need to use the string function strip_tags (), can solve, then how to use this function, this article will take you to understand the php strip_ tags () function.
The definition and usage of PHP strip_tags () function
The Strip_tags () function strips HTML, XML, and PHP tags from the string.
Grammar
Strip_tags (String,allow)
Detailed parameters:
The string argument is a character set to be checked and must have
Allow is not a required parameter, it is a specified string in which tags are allowed, and these tags are not deleted. Do not fill in the default remove all labels
PS: Note: This function always strips HTML comments. This cannot be changed by the Allow parameter.
return value
The Strip_tags () function returns the stripped string.
Example One
Use the Strip_tags () function to remove HTML tags from the string, as follows:
<?php$name= "Hello <b>world!</b>"; $tags =strip_tags ($name); Echo $name. " <br/> "; echo $tags before removing HTML tags; ?> after removing HTML tags
Code Run output Result:
Example Two
Use the Strip_tags () function to remove HTML tags from the string, but allow <b> tags, as shown in the code below
<?php$name= "Hello <b><i>world!</i></b>"; $tags =strip_tags ($name, "<b>"); echo $ Name. " <br/> "; echo $tags before removing HTML tags; ?> after removing HTML tags
Code Run output Result:
"Related articles recommended"
One detail to note when using the PHP strip_tags () function
Use the PHP strip_tags () function to keep multiple HTML tag instances detailed