Brief introduction to htmlspecialchars, strip_tags, and addslashes functions in php

Source: Internet
Author: User
In web application development, htmlspecialchars, strip_tags, and addslashes functions are the most common functions. This article will introduce these functions separately. In web application development, htmlspecialchars, strip_tags, and addslashes functions are the most common functions. This article will introduce these functions separately.

1. strip_tags () function

The strip_tags () function removes HTML, XML, and PHP tags from strings.

Example

 world!";$tags=strip_tags($name);echo $tags;                        ?>

2. htmlspecialchars () function

The htmlspecialchars () function converts predefined characters into HTML objects.

Specifically, this function converts the following characters:

  • & (And) &

  • "(Double quotation marks)"

  • <(Less than) to <

  • > (Greater than) to>

Example

 bold text.";echo htmlspecialchars($str);?>

3. htmlentities () function

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. Not powerful

Example

 ";echo htmlentities($str);?>

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

[Recommended related articles]

Detailed description of the strip_tags () function example for removing string tags from php

Php addslashes () function and stripslashes () function example

Differences between php htmlspecialchars () and strip_tags functions

The above is a brief introduction to htmlspecialchars, strip_tags, and addslashes functions in php. For more information, see other related articles in the first PHP community!

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.