addslashes – PHP String Functions

Syntax :

string addslashes(string);

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 :
$strExample = addslashes('Hi "from" tutorialmines.');

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 –

Hi \”from\” tutorialmines.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *