Difference between strip_tags and htmlspecialchars in removing html tags from php
| This article introduces the differences between strip_tags and htmlspecialchars, which are two functions for removing html tags in php. For more information, see.
First, let's look at the strip_tags function. Remove HTML and PHP tags. Syntax: string strip_tags (string str); return value: string function type: data processing content description this function removes any HTML and PHP Mark strings contained in the string. If the HTML and PHP tags of a string are incorrect, for example, if a greater symbol is missing, an error is returned. This function has the same function as fgetss.
Let's take a look at the htmlspecialchars function. Convert special characters to HTML format. Syntax: string htmlspecialchars (string); return value: string function type: data processing. in this function, special characters are converted to the string format of HTML (&....;). The most common use case may be the message board for handling customer messages. Convert & (and) to & "(double quotation marks) to" <(less than) to <> (greater than) to> ''(single quotation marks) to 'this function only converts the preceding special characters, not all are converted to the ASCII conversion defined in HTML.
Example:
Output result: Test |