The json_encode function can be used to add slashes to double quotes. Also ‘addcslahses’ can also be used to add ‘\’ to specific characters −
Example
<?php $str = addcslashes("Hello there!","t"); echo($str); ?>
Output
This will produce the following output −
Hello \there!
The ‘addcslashes’ function is used to return a string with backslashes in front of the specific characters. It is a case sensitive function and should usually not be used with 0 (null), r (carriage return), n (newline), f (form read), t (tab), v (vertical tab) values. This is because values like \0, \r, \n, \t, \f and \v are pre-define escape sequences.
In the above code, the ‘addcslashes’ function is called on the string by specifying that the backslash has to occur before the character ‘t’.