PHP addslashes Function
PHP

PHP addslashes Function

Editorial Team
Editorial Team

Follow us on Discord or Telegram to get access to free tutorials and updates.

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.