Home > Backend Development > PHP Tutorial > Addslashes() and stripslashes() in PHP implement string escape and restoration usage examples, usage of escape characters_PHP tutorial

Addslashes() and stripslashes() in PHP implement string escape and restoration usage examples, usage of escape characters_PHP tutorial

WBOY
Release: 2016-07-12 09:01:20
Original
1501 people have browsed it

Usage examples of addslashes() and stripslashes() in PHP to implement string escape and restoration, usage of escape characters

This article describes the examples of addslashes() and stripslashes in PHP () implements string escape and restoration usage. Share it with everyone for your reference, the details are as follows:

The addslashes() function in PHP returns a string with a backslash added before predefined characters.

The predefined characters are:

Single quote (')
Double quotes (")
backslash()
NULL

The stripslashes() function removes the backslashes added by the addslashes() function.

Usage examples are as follows:

<&#63;php
 $str="select * from `book` where bookname='帮客之家'";
 echo $str."<br/>";//输出字符串$str
 echo $astr=addslashes($str);//字符串转义并输出
 echo "<br/>";
 echo stripslashes($astr);//将转义字符串还原
&#63;>

Copy after login

The running results are as follows:

select * from `book` where bookname='帮客之家'
select * from `book` where bookname=\'帮客之家\'
select * from `book` where bookname='帮客之家'

Copy after login

Supplement:

The difference between addslashes() and addcslashes() functions:

These are two functions that are very similar in writing but have different uses. The addslashes() function returns a string with a backslash added before the predefined characters, while the addcslashes() function returns a string with a backslash added before the specified character. string, so the addcslashes() function needs to add additional parameters indicating the specific characters that need to be added with backslashes.

For the specific differences and usage between the two, please refer to the relevant article on this site "Analysis of the Difference and Comparison of PHP addslashes() and addcslashes() Functions"

I hope this article will be helpful to everyone in PHP programming.

Articles you may be interested in:

  • The addslashes function in PHP and SQL injection prevention
  • Analysis of the security principles of using addslashes function escaping in PHP
  • PHP’s explanation of htmlspecialchars, strip_tags, and addslashes
  • The difference between PHP function addslashes and mysql_real_escape_string
  • The difference between php stripslashes and addslashes
  • Analysis of php addslashes() and addclashes() Differences and comparisons of functions
  • What are the differences between php daddslashes() and saddslashes() Analysis
  • php addslashes and other methods of clearing spaces are unsafe
  • php addslashes and mysql_real_escape_string
  • php addslashes function detailed analysis and description
  • Usage analysis of addcslashes and stripcslashes functions in PHP

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1089584.htmlTechArticleAddslashes() and stripslashes() in PHP implement string escape and restoration usage examples, usage of escape characters The examples in this article describe how addslashes() and stripslashes() in PHP implement string escaping and...
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template