PHP's interpretation of Htmlspecialchars, Strip_tags, addslashes _php skills

Source: Internet
Author: User
Tags html tags

PHP htmlspecialchars, Strip_tags, addslashes is a common function in Web page program development, today to detail the use 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 the string are wrong, such as less than the symbol greater than, it will return the error. This function has the same function as FGETSS (). Fgetss reads files from a file and removes HTML and PHP tags.

2. function htmlspecialchars, converting special characters into HTML format

Specifically, this function converts the following characters:

& (and) Convert to &
"(double quotes) into"
< (less than) turn into <
> (greater than) convert to >

3. function Htmlentities, turn all the characters into HTML strings

Maybe you're still sorry. Htmlspecialchars can only handle 4 HTML tags, so now you don't regret it, htmlentities is converting all the characters. It's not as strong as it seems, but it doesn't seem to be very meaningful to me.

4. Function stripslashes and addslashes are a pair, addslashes refers to a string using backslashes, Stripslashes is a string that restores addslashes references.

This function is typically a necessary step before a database query, which is preceded by a backslash for the needs of database query statements. These characters are single quotes ('), double quotes ("), backslashes (/) and NUL (NULL characters).

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.