PHP explanation of htmlspecialchars, strip_tags, and addslashes _ PHP Tutorial

Source: Internet
Author: User
PHP explanations of htmlspecialchars, strip_tags, and addslashes. Htmlspecialchars, strip_tags, and addslashes of PHP are common functions in Web application development. today we will detail the usage of these functions: 1. strip_tags: htmlspecialchars, strip_tags, and addslashes of PHP with HTML and PHP removed are common functions in Web application development. today we will detail the usage of these functions:

1. function strip_tags: remove HTML and PHP tags

Note: This function removes any HTML and PHP tag 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 and fgetss () have the same functions. Fgetss reads the file from the file and removes the html and php markup.

2. the htmlspecialchars function converts special characters to HTML format.

Specifically, this function converts the following characters:

& (And) &
"(Double quotation marks)"
<(Less than) to <
> (Greater than) to>

3. the htmlentities function converts all the elements into HTML strings.

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. It cannot be said to be powerful, but it is of little significance to me.

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 ).

Example 1. function strip_tags: remove HTML and PHP...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.