Examples of string escape and restore usages implemented in PHP addslashes and stripslashes

Source: Internet
Author: User
Tags php programming
Examples in this article describe the use of addslashes () and stripslashes () in PHP for string escaping and restoration. Share to everyone for your reference, as follows:

The addslashes () function in PHP returns a string that adds a backslash before a predefined character.

The predefined characters are:

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

the Stripslashes () function deletes a backslash added by the addslashes () function .

The usage examples are as follows:

<?php $str = "Select * from ' book ' where Bookname= ' the site '"; echo $str. "
";//output String $str echo $astr =addslashes ($STR);//string escape and Output echo"
"; echo stripslashes ($ASTR);//Will escape string restore?>

The results of the operation are as follows:

SELECT * from ' book ' where Bookname= ' this station ' select * from the ' book ' where bookname=\ ' this station \ ' select * from ' book ' where Bookname= ' this station '

Add:

Addslashes () differs from the Addcslashes () function:

This is two very similar. but using a different function, the addslashes () function returns a string that adds a backslash before the predefined character, and the Addcslashes () function returns a string that adds a backslash before the specified character, so addcslashes () The function needs to add additional parameters that describe the specific characters that need to be added with backslashes.

The two specific differences and usage can refer to the relevant articles of this site "parsing PHP addslashes () and addcslashes () functions of the difference and comparison"

I hope this article is helpful to you in PHP programming.

The above describes the PHP addslashes and stripslashes implementation of the string escape and restore usages, including the contents of the content, I hope the PHP tutorial interested in a friend helpful.

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