In PHP, you can use the addslashes() function to escape backslashes. This function can return a string with a backslash added before predefined characters. The predefined characters include single quotes, double quotes, and backslashes. Slashes and NULL, the syntax is "addslashes (backslash string that needs to be escaped)".
The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer
addslashes() function returns a string with backslashes added before predefined characters.
The predefined characters are:
Single quotation mark (')
Double quotation mark (")
Backslash (\)
NULL
Tip: This function can be used to return the Strings and database query statement preparation strings.
The syntax is:
addslashes(string)
string required. Specifies the string to be escaped.
Return value: Returns escaped String.
The example is as follows:
<?php $str = addslashes('这句话的中间\有一个反斜杠,现在给他转义了'); echo($str); ?>
Output result:
Recommended learning: "PHP Video Tutorial》
The above is the detailed content of How to escape backslash in php. For more information, please follow other related articles on the PHP Chinese website!