The addslashes() function is an inbuilt function in PHP and it returns a string with backslashes in front of predefined characters. It does not take any specified characters in the parameter.
The predefined characters are:
- single quote (‘)
- double quote (“)
- backslash (\)
Note: The addslashes() function is different from addcslashes() function accepts specified characters before which be want to add slashes but the addslashes() function doesnot accepts any character in parameters, rather it adds slashes before some specified characters.
Parameters: The addslashes() function accepts only one parameter $string which specifies the input string which is needed to be escaped. We can also say that this parameter specifies a string in which we want to add backslashes before the pre-defined characters.
Return value: It returns the escaped string with backslashes in front of the pre-defined characters which is passed in the parameter.
Input : $string = "Geek's" Output : Geek\'s Input : $string='twinkle loves "coding"' Output : twinkle loves \"coding\"
Below programs illustrate the addslashes() function in PHP:
twinkle loves \"coding\"
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.