Htmlspecialchars, Strip_tags, addslashes functions are the most common in the development of web-based programs, and this article will introduce these three functions separately.
1.strip_tags () function
The Strip_tags () function strips HTML, XML, and PHP tags from the string.
Example
<?php$name= "Hello <b>world!</b>"; $tags =strip_tags ($name); Echo $tags; >
2.htmlspecialchars () function
The Htmlspecialchars () function converts pre-defined characters to HTML entities.
Specifically, this function translates the following characters:
& (and) turn into &
"(double quotation marks) to turn"
< (less than) turn into <
> (greater than) turn into >
Example
<?php$str = "This is some <b>bold</b> text."; echo Htmlspecialchars ($STR);? >
3.htmlentities () function
Perhaps you are still sorry htmlspecialchars can only handle 4 HTML tags, so now you do not regret, htmlentities is to convert all characters. Not very powerful.
Example
<?php$str = "<?" Php?h???? > Echo htmlentities ($str);? >
4. Function stripslashes and addslashes are a pair, addslashes is to use a backslash reference string, Stripslashes is a string that restores addslashes references.
This function is generally a necessary step before a database query, which is preceded by a backslash in order for the database query statement to be preceded by some characters. These characters are single quotes ('), double quotation marks ("), backslashes (/), and NUL (the NULL character).
"Related articles recommended"
PHP Removal string tag strip_tags () Function Example detailed
PHP addslashes () function and stripslashes () function examples
The difference between PHP htmlspecialchars () and Strip_tags functions