How to understand htmlspecialchars, strip_tags and addslashes of PHP
This article mainly explains "how to understand PHP htmlspecialchars, strip_tags, addslashes", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's learn how to understand PHP htmlspecialchars, strip_tags, addslashes.
1. Function strip_tags: remove HTML and PHP tags
Note: This function removes any HTML and PHP markup strings contained in the string. Errors are also returned if the HTML and PHP tags of the string are wrong, such as missing greater than symbols. This function has the same function as fgetss(). Fgetss reads files from files and removes html and php tags.
2. htmlspecialchars converts special characters to HTML format
Specifically, this function converts the following characters:
& (and) turned into &
" (double quotes) to"
< (小于) 转成 < >(greater than) converted to>
3. htmlentities converts all characters into HTML strings
You may regret that htmlspecialchars can only handle four html tags, but htmlentities converts all characters. It's not powerful, but it doesn't mean much to me.
4. The stripslashes and addslashes functions are a pair, addslashes refers to strings using backslashes, and stripslashes restores strings referenced by addslashes.
This function is usually a necessary step to be processed before a database query. The string is preceded by backslashes for database query statements and so on. These characters are single quotes ('), double quotes ('), backslashes (/), and NULs (NULL characters).
At this point, I believe that everyone has a deeper understanding of "how to understand PHP htmlspecialchars, strip_tags, addslashes". Let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!