Addslashes () and stripslashes () in PHP implement string escape and restore usage instances _php tips

Source: Internet
Author: User

This article describes the Addslashes () and stripslashes () implementation string escape and restore usage in PHP. Share to everyone for your reference, specific as follows:

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

Predefined characters are:

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

the Stripslashes () function deletes the backslash that was added by the addslashes () function .

Examples of usage are as follows:

<?php
 $str = "Select * from ' book ' Where Bookname= ' cloud-dwelling community '";
 echo $str. " <br/>/output string $str
 echo $astr =addslashes ($STR);//String escaping and outputting
 echo "<br/>";
 echo stripslashes ($ASTR);//Restore the escaped string
?>

The results of the operation are as follows:

SELECT * from ' book ' Where Bookname= ' cloud Communities '
select * from ' book ' Where bookname=\ ' yun-Habitat Community \ '
select * ' book ' whe Re bookname= ' cloud-dwelling community '

Add:

The difference between the addslashes () and the Addcslashes () function:

It's two very close. 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 to describe the specific characters that need to be added to the backslash.

The difference and usage of the two can refer to the difference and comparison between the analytic PHP addslashes () and the Addcslashes () function.

I hope this article will help you with the PHP program design.

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.