The addslashes() function returns the string with backslashes in front of predefined characters. It returns a string with backslashes in front of predefined characters.
The predefined characters are the following: single quote ('), double quote ("), backslash (\) and NULL
Syntax
addslashes(str)
Parameters
str − Specifies the string to be escaped
Return
The addslashes() function returns a string with backslashes in front of predefined characters.
Example
The following is an example −
<?php $s = "Who's Tom Hanks?"; echo $s . " Unsafe for database query!<br>"; echo addslashes($s) . " Safe in a database query!"; ?>
Output
Who's Tom Hanks? Unsafe for database query! Who\'s Tom Hanks? Safe in a database query!
Example
Let us see another example −
<?php $s = addslashes('Cricket is a “religion” in India.'); echo($s); ?>
Output
Cricket is a “religion” in India.