In web application development, htmlspecialchars, strip_tags, and addslashes functions are the most common functions. This article will introduce these functions separately. In web application development, htmlspecialchars, strip_tags, and addslashes functions are the most common functions. This article will introduce these functions separately.
1. strip_tags () function
The strip_tags () function removes HTML, XML, and PHP tags from strings.
Example
world!";$tags=strip_tags($name);echo $tags; ?>
2. htmlspecialchars () function
The htmlspecialchars () function converts predefined characters into HTML objects.
Specifically, this function converts the following characters:
Example
bold text.";echo htmlspecialchars($str);?>
3. htmlentities () function
Maybe you are still sorry that htmlspecialchars can only process four html tags, so now you should not regret it. htmlentities is to convert all characters. Not powerful
Example
";echo htmlentities($str);?>
4. the stripslashes function is a pair with addslashes. addslashes uses a backslash to reference strings, and stripslashes is used to restore the strings referenced by addslashes.
This function is generally a necessary step for processing before database queries. this string is added with a backslash before certain characters for database query statements. These characters are single quotation marks ('), double quotation marks ("), backslash (/), and NUL (NULL ).
[Recommended related articles]
Detailed description of the strip_tags () function example for removing string tags from php
Php addslashes () function and stripslashes () function example
Differences between php htmlspecialchars () and strip_tags functions
The above is a brief introduction to htmlspecialchars, strip_tags, and addslashes functions in php. For more information, see other related articles in the first PHP community!