PHP addslashes Function

The PHP addslashes function is used to add backslashes in front of some predefined characters in a string. This function is case-sensitive.

PHP addslashes Function

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.


Share Tweet Send
0 Comments
Loading...