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)

Example

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

Syntax

addslashes(str)

Parameter Values

ValueTypeExplanation
strRequiredSpecifies the string to be escaped.

Return Value

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

Reminder

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