Home >Backend Development >PHP Tutorial >PHP explanation about htmlspecialchars, strip_tags, addslashes_PHP tutorial
PHP’s htmlspecialchars, strip_tags, and addslashes are common functions in web program development. Today we will describe the usage of these functions in detail:
1. Function strip_tags: remove HTML and PHP tags
Note: This function can remove any HTML and PHP tag strings contained in the string. If the HTML and PHP tags of the string are originally wrong, for example, the greater than symbol is missing, an error will also be returned. This function has the same function as fgetss(). fgetss reads the file from the file and removes the html and php tags.
2. Function htmlspecialchars, convert special characters into HTML format
Specifically, this function will convert the following characters:
& (and) is converted to &
" (double quotes) is converted to "
< (less than) is converted to <
> (greater than) is converted to >
3. Function htmlentities, convert all characters into HTML strings
Maybe you are still regretting that htmlspecialchars can only process 4 html tags, so don't regret it now, htmlentities converts all characters. It's not unpowerful, but it doesn't mean much in my opinion.
4. The functions stripslashes and addslashes are originally a pair. addslashes uses backslashes to quote strings, and stripslashes restores the string quoted by addslashes.
This function is generally a necessary step that needs to be processed before database query. This string has a backslash before certain characters for the needs of database query statements, etc. These characters are single quote ('), double quote ("), backslash (/) and NUL (NULL character).