PHP addslashes Function

PHP addslashes Function

Mishel Shaji
Mishel Shaji

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
  • NULL

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.


    $data = "That is John's PC";
    echo addslashes($data);


That is John\'s PC

Learn more about other PHP string handling functions.