In PHP, addslashes () and stripslashes () are used for string conversion and restoration. usage of escape characters _ PHP Tutorial

Source: Internet
Author: User
In PHP, addslashes () and stripslashes () are used for string conversion and restoration. Examples of character string conversion and restoration using addslashes () and stripslashes () in PHP. Examples of this article describe the use of escape characters in PHP: addslashes () and stripslashes () implement string conversion and PHP addslashes () and stripslashes () to implement string conversion and restoration. use escape characters

The example in this article describes how to convert and restore strings using addslashes () and stripslashes () in PHP. We will share this with you for your reference. The details are as follows:

In PHP, the addslashes () function returns a string that adds a backslash before a predefined character.

The predefined characters are:

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

The stripslashes () function deletes the backslash added by the addslashes () function.

Example:

<? Php $ str = "select * from 'book' where bookname = 'House of help'"; echo $ str ."
"; // Output string $ str echo $ astr = addslashes ($ str); // escape string and output echo"
"; Echo stripslashes ($ astr); // restore the escape string?>

The running result is as follows:

Select * from 'book' where bookname = ' 'select * from 'book' where bookname = \' \ 'select * from 'book' where bookname = '''

Supplement:

Differences between addslashes () and addcslashes () functions:

These two functions are very similar in writing but use different functions. the addslashes () function returns a string that adds a backslash before a predefined character, while the addcslashes () function () the function returns a string that adds a backslash before a specified character. Therefore, the addcslashes () function needs to add additional parameters to indicate that the specific character of the backslash needs to be added.

For details about the differences and usage of the two, refer to the article "differences and comparison between parsing php addslashes () and addcslashes () functions".

I hope this article will help you with PHP programming.

Articles you may be interested in:
  • Php addslashes functions and SQL anti-injection
  • Analysis on the security principle of escaping using the addslashes function in PHP
  • PHP explanation of htmlspecialchars, strip_tags, and addslashes
  • Differences between PHP functions addslashes and mysql_real_escape_string
  • Differences between php stripslashes and addslashes
  • Differences and comparison between php addslashes () and addclashes () functions
  • What are the differences between php daddslashes () and saddslashes ()?
  • Php addslashes and other methods for clearing spaces are insecure.
  • Php addslashes and mysql_real_escape_string
  • Php addslashes function detailed analysis description
  • Analysis of addcslashes and stripcslashes functions in PHP

Conversion () and stripslashes () implement string conversion and restoration usage examples. the usage of escape characters in this article describes the use of addslashes () and stripslashes () in PHP to realize string conversion and conversion...

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.