The PHP addslashes function is used to add backslashes in front of some predefined characters in a string. This function is case-sensitive.
Following are the predefined characters that works with this function.
- ‘ – single quote
- ” – double quote
- \ – backslash
The addslashes function can be used when you want to prepare a string for database insertion.
The function takes a string as the parameter.
- string – Required
- Returns the escaped string.
<?php $data = "That is John's PC"; echo addslashes($data); ?>
That is John\'s PC
Learn more about other PHP string handling functions.