PHP addslashes() Function

Last Updated:

PHP addslashes()

The addslashes() function is used to add backslashes before the characters that need to be escaped.

Note: The predefined characters are:

  • single quotes (')
  • double quote (")
  • backslash (\)
  • NUL (the NUL byte - \0)

Example

PHP Compiler
<?php $str = "She is a 'good' dancer"; echo addslashes($str); ?>

Syntax

addslashes(str)

Parameter Values

ValueTypeExplanation
str Required Specifies the string to be escaped.

Return Value

ValueExplanation
Number Returns a string with backslashes added before characters that need to be escaped.

More Example

Example

PHP Compiler
<?php echo addslashes("Using ' single quote <br>"); echo addslashes('Using " double quote <br>'); echo addslashes("Using \ backslash <br>"); echo addslashes('Using \0 (NUL byte)<br>'); ?>

Share this Page

Meet the Author