Addslashes and Stripslashes functions

Source: Internet
Author: User

The Addslashes () function returns a string that adds a backslash before a predefined character.

The predefined characters are:

    • Single quotation mark (')
    • Double quotation marks (")
    • Back slash (\)
    • Null
Echo "Who's Bill Gates?<br>"echo  addslashes("Who's Bill Gates?")

Results:

Who '

The second automatically adds a backslash in front of the single quotation mark. If the string is in storage, there are single quotes inside it, and SQL injection may be used for security purposes.

Note: By default, PHP automatically runs Addslashes () for all GET, POST, and COOKIE data. So you should not use Addslashes () for a string that has been escaped, because this results in double-layer escaping. You can use the function GET_MAGIC_QUOTES_GPC () to detect this situation.

1. Ini_set (MAGIC_QUOTES_GPC) Gets the configuration information for MAGIC_QUOTES_GPC, if this value is True

All ' (single quotes), "(double quotes), \ (backslash), and NUL ' s are automatically escaped by a backslash.

For example, the data you received on the table dropdowns submission Xiaoming's dog server is Xiaoming\ 's dog

2. Stripslashes dereference A reference string it's going to go.

The stripslashes function in PHP means that the backslash character in the string is removed, and if there are two consecutive backslashes, only one is removed; the example is as follows:

Echo stripslashes ("Hello everybody, here is \" "Baidu Quiz platform \"!) "); // output: Hello everyone, here is "Baidu Quiz platform"! 

Addslashes and Stripslashes functions

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.