PHP addslashes() Function

You are Here:

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)


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


She is a \'good\' dancer



Parameter Values

strRequiredSpecifies the string to be escaped.

Return Value

NumberReturns a string with backslashes added before characters that need to be escaped.

More 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>'); ?>


Using \' single quote Using \" double quote Using \\ backslash Using \\0 (NUL byte)


Hi Developers, we almost covered 90% of String functions and Interview Question on PHP with examples for quick and easy learning.

We are working to cover every Single Concept in PHP.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author