PHP string Escape function (addslashes,stripslashes) detailed _php tutorial

Source: Internet
Author: User
In PHP, there are two functions that are related to the escape of a string, they are addslashes and stripslashes respectively.

Addslashes ($string) to add a backslash (\) before the specified predefined character to prepare the appropriate string for the string stored in the database and for the database query statement.

Note: By default, PHP instruction MAGIC_QUOTES_GPC is on, and automatically runs Addslashes () for all GET, POST, and COOKIE data. Do not use Addslashes () for strings that have been MAGIC_QUOTES_GPC escaped, because this results in double-layer escaping. You can use the function GET_MAGIC_QUOTES_GPC () to detect this situation.

Stripslashes ($string), which is the inverse of addslashes (), is used to remove the backslash added by the addslashes () function to restore the escaped character, also known as reversal semantics, primarily for cleaning up data retrieved from a database or HTML form.

So what characters will addslashes be escaped, as follows:

Single quotation mark (')
Double quotation marks (")
Back slash (\)
Null

In addition, a string with a single quote delimiter, supports two escape characters:

Single quotation mark (')
Back slash (\)

A string with a double quote delimiter that supports the following escapes:

\ n line break (LF or ASCII characters 0x0A (10))
\ r Enter (CR or ASCII character 0x0D (13))
\ t Horizontal tab (HT or ASCII character 0x09 (9))
\ \ Backslash
\$ dollar Sign
\ "Double quotation marks
\[0-7]{1,3} This regular expression sequence matches a character represented by an octal symbol
\x[0-9a-fa-f]{1,2} This regular expression sequence matches a character that is represented by a hexadecimal symbol

Articles you may be interested in

    • PHP string substitution function str_replace faster than preg_replace
    • String processing function in PHP (string Functions) Full summary
    • PHP Performance Optimizations: Use Isset () to determine string length faster than strlen ()
    • Escape,encodeuri,encodeuricomponent comparison and analysis of JavaScript's string encoding function
    • Some of the powerful string handling functions that PHP has forgotten
    • PHP Filter String functions
    • PHP's most accurate string-length intercept function
    • PHP generates consecutive numbers (Letters) array function range () analysis, PHP lottery program function

http://www.bkjia.com/PHPjc/764092.html www.bkjia.com true http://www.bkjia.com/PHPjc/764092.html techarticle in PHP, there are two functions that are related to the escape of a string, they are addslashes and stripslashes respectively. Addslashes ($string), add a backslash (\) before the specified predefined character, with ...

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