PHP addslashes Function
PHP

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.

Syntax

addslashes(string);

The function takes a string as the parameter.

  • string – Required
  • Returns the escaped string.

Example

<?php
    $data = "That is John's PC";
    echo addslashes($data);
?>

Output

That is John\'s PC

Learn more about other PHP string handling functions.