PHP addslashes () and Stripslashes () implement string escape and restore usages, escape character usage _php tutorial

Source: Internet
Author: User

PHP addslashes () and Stripslashes () implement string escape and restore usages, use of escape characters


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= ' house of Help '"; 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= ' home ' select * from ' book ' where bookname=\ ' help home \ ' select * from ' book ' where bookname= ' Home for the guests '

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.

Articles you may be interested in:

    • addslashes function and SQL anti-injection in PHP
    • Analysis of security principle of using addslashes function escaping in PHP
    • PHP explanations for Htmlspecialchars, Strip_tags, addslashes
    • The difference between PHP functions Addslashes and mysql_real_escape_string
    • The difference between PHP stripslashes and addslashes
    • Parsing the differences and comparisons between PHP addslashes () and addclashes () functions
    • What are the different analyses of PHP daddslashes () and saddslashes ()?
    • PHP addslashes and other ways to clear the space are unsafe
    • PHP addslashes and Mysql_real_escape_string
    • PHP addslashes function Detailed Analysis description
    • Analysis of addcslashes and stripcslashes function usage in PHP

http://www.bkjia.com/PHPjc/1089584.html www.bkjia.com true http://www.bkjia.com/PHPjc/1089584.html techarticle php addslashes () and stripslashes () implement the string escape and restore usages instance, the use of escape characters in this article describes PHP addslashes () and stripslashes () to implement the string escape and ...

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