PHP Tutorial > String Functions > addslashes Function
The PHP addslashes function is used to add slashes to certain characters in a string. Those characters are single quote ('), double quote ("), and the NULL character. This function is useful when we try to insert strings into a database.
The syntax of the addslashes function is:
Let's take a look at the examples below:
print addslashes ('1keydata');
In Example 1, nothing changes because the string does not contain single quote, double quote, or the NULL character.
print addslahes ('She said, "Great!"');
She said, \"Great!\"
In Example 2, a backslash is added to the left of the double quotes.
Next: PHP echo Function