PHP addslashes() Function
PHP addslashes() Function
The addslashed() function in PHP is used to return a string with backslashes in front of predefined characters. This function is only used with some characters which are as follows:
- single quote (')
- double quote (")
- backslash (\)
- NULL (the NUL byte)
Syntax
addslashes(str)
Parameter
str(required)- This parameter represents the string to be escaped.
Return
This function returns a string with backslashes added before characters that need to be escaped.
Example 1
Output
Original string:Welcome to my "PHP" world After using the addslashes() function... The new string: Welcome to my \"PHP\" world
Example 2
Output
Original string 1:Hllo' World Hllo' World Original string 2:Hllo''my' world Hllo\'\'my\' world
Example 3
Output
original stringRahul's uncle name is Alber Dumbledore After the addslashes() method... Rahul\'s uncle name is Alber Dumbledore
Example 4
Output
Original string: After the addslashes() method... New String: