PHP addslashes() function is used to add backslashes in a given string before some predefine characters. The return type of this function is a string
These predefined characters are:
- Single quote[']
- Double quote["]
It is an inbuilt function of PHP which most commonly used in database queries to remove single quote related issues.
NOTE: To add backslashes before user define characters in a string use addcslashes() function.
$string is a PHP string.
<?php $string="Ram's son goes to his school every morning."; $new_string=addslashes($string); echo "Old string is : $string <br>"; // it will not work in database query as data echo "New String is :$new_string"; // it will not give any error in database query ?>