PHP string escape functions (addslashes, stripslashes) _ PHP Tutorial

Source: Internet
Author: User
PHP string escape functions (addslashes, stripslashes. In PHP, there are two functions related to the escape of strings: addslashes and stripslashes. Addslashes ($ string): add a backslash () before the specified predefined character. in PHP, two functions are related to the escape of the string. they are addslashes and stripslashes.

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

Note: By default, the magic_quotes_gpc command of PHP is on, and addslashes () is automatically run for all GET, POST, and COOKIE data (). Do not use addslashes () for strings that have been escaped by magic_quotes_gpc, because this causes double-layer escape. In this case, you can use the get_magic_quotes_gpc () function for detection.

Stripslashes ($ string) is the inverse function of addslashes (). it is used to delete the backslash added by the addslashes () function to restore the characters to be escaped. it is also called inverse meaning, it is mainly used to clear data retrieved from a database or HTML form.

Which characters will addslashes escape:

Single quotes (')
Double quotation marks (")
Backslash (\)
NULL

In addition, strings with single quotes as delimiters support two escape characters:

Single quotes (')
Backslash (\)

Strings with double quotation marks as delimiters support the following escape characters:

\ N line feed (LF or ASCII character 0x0A (10 ))
\ R press enter (CR or ASCII character 0x0D (13 ))
\ T horizontal tab (HT or ASCII character 0x09 (9 ))
\ Backslash
\ $ Dollar Sign
\ "Double quotation marks
\ [0-7] {} the regular expression sequence matches a character represented by the octal symbol
\ X [0-9A-Fa-f] {} this regular expression matches a sequence of characters represented by a Hexadecimal Symbol

Articles you may be interested in
  • Php string replacement function str_replace is faster than preg_replace
  • Summary of String Functions in PHP
  • Php performance optimization: using isset () to determine the string length is faster than strlen ()
  • Comparison and analysis of string encoding functions escape, encodeURI, and encodeURIComponent in javascript
  • Some powerful string processing functions forgotten by php
  • Php string filter function
  • Php's most precise string length truncation function
  • PHP generates continuous numbers (letters) array function range () analysis, PHP lottery program function

Addslashes and stripslashes. Addslashes ($ string), add a backslash (\) before the specified predefined character,...

Related Article

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.