PHP addslashes() Function
The PHP addslashes() function returns a string with backslashes in front of predefined characters. The predefined characters are:
- Single quote (')
- Double quote (")
- Backslash (\)
- NULL (the NULL byte)
Syntax
addslashes(string)
Parameters
string |
Required. Specify the string to be escaped. |
Return Value
Returns the escaped string.
Example:
The example below shows the usage of addslashes() function.
<?php $str = 'John loves "Programming"'; //returns: John loves \"Programming\" echo addslashes($str); ?>
The output of the above code will be:
John loves \"Programming\"
Example:
Consider one more example on addslashes() function.
<?php $str = "John's A/C number is '1234'"; //returns: John\'s A/C number is \'1234\' echo addslashes($str); ?>
The output of the above code will be:
John\'s A/C number is \'1234\'
❮ PHP String Reference