The Addslashes () function in PHP is to add a backslash before some of the predefined characters in the input string, but if you find yourself
using PHP addslashes function error,Then you need to take a good look at your code. If you don't believe me, please look at the code below.
<?phpecho function_exists (' addcslashes ');//detects if the function is present in echo GET_MAGIC_QUOTES_GPC (). ' <br/> ';//detect if Automatic escape echo php_version is turned on. ' <br/> ';//php version information echo addcslashes ("Who's John Adams?"); Echo ' <br/> '; $str = "Who's John Adams?"; echo addslashes ($STR);? >
What is the result of the above code running?
The result of the code operation:
We can see from the above running results:
One error, another normal output. Why is it?
PS: If you run the results without error message, you need to set up your PHP error level can see, about how to set the error level of PHP, please refer to this article: PHP How to set the error level?
Because Addslashes and addcslashes are not the same function, it is found that there is only one character difference. But the functions of the two functions are the same-escaping the string.
What is the difference between addslashes and addcslashes?
Addslashes only one parameter-string
Addcslashes requires two parameters, a string, and a delimiter.
Echo Addcslashes ("Who s John Adams?", "'");
This will allow the normal output of the write.
The code is as follows:
<?phpecho function_exists (' addcslashes ');//detects if the function is present in echo GET_MAGIC_QUOTES_GPC (). ' <br/> ';//detect if Automatic escape echo php_version is turned on. ' <br/> ';//php version information echo addcslashes ("Who's John Adams?", ""); Echo ' <br/> '; $str = "Who's John Adams?"; echo addslashes ($STR);? >
Code Run Result:
Summary: Hope this article can help you understand the use of addslashes.
1.php addslashes () function and stripslashes () function Example
Examples of the difference between the 2.php stripslashes () function and the addslashes () function