addslashes – PHP String Functions
Syntax :
Description :
addslashes function will add backslash ( \ ) before the predefined characters.
The predefined characters are:
- single quote (‘)
- double quote (“)
- backslash (\)
- NULL
Parameter :
string – which needs to be escaped for predefined characters.
Output :
This will return the escaped string hence adding slashes before the predefined characters in string.
Related articles : addcslashes(), stripcslashes(), stripslashes(), htmlspecialchars().
addslashes – PHP Functions Example 1 :
<?php $strExample = addslashes('Hi "from" tutorialmines.'); echo($strExample); ?>
In above example ,We have string “Hi from tutorialmines.” Now this function will escape letter (‘) single quote.
When we apply it. This will add backslash(\) in front of every predefined character i.e from. Now Output will become –