Question #6302   Submitted by Answiki on 06/22/2022 at 07:36:35 PM UTC

What is the purpose of the addslashes() function in PHP?

Answer   Submitted by Answiki on 06/22/2022 at 07:39:33 PM UTC

The PHP function addslashes() is used to escape special characters from a string. The function automatically adds a backslash before each of the following characters:

  • single quote ( ' )
  • double quote ( " )
  • backslash ( \ )
  • the NUL character


For example:

$string = 'He says "John".';
$string = addslashes ($string);

// Displays: He says \"John\".
echo $string;

See also:


4 events in history
Question by Answiki 06/22/2022 at 07:39:54 PM
How to escape special characters in PHP?
Answer by Answiki on 06/22/2022 at 07:39:33 PM

The PHP function addslashes() is used to escape special characters from a string. The function automatically adds a backslash before each of the following characters:

  • single quote ( ' )
  • double quote ( " )
  • backslash ( \ )
  • the NUL character


For example:

$string = 'He says "John".';
$string = addslashes ($string);

// Displays: He says \"John\".
echo $string;

See also:


Question by Answiki 06/22/2022 at 07:36:35 PM
What is the purpose of the addslashes() function in PHP?
Question by Answiki 06/22/2022 at 07:36:29 PM
What is the purpose of the addslashes function in PHP?
# ID Query URL Count

Icons proudly provided by Friconix.