addslashes() function in PHP || PHP adslashes function

addslashes() function in php

Last Updated by Pooja Chikara 27-Apr-20

0 358

PHP addslashes() function is used to add backslashes in a given string before some predefine characters. The return type of this function is a string

These predefined characters are:

  • Single quote[']
  • Double quote["]
  • Backslash[\]

It is an inbuilt function of PHP which most commonly used in database queries to remove single quote related issues.

NOTE: To add backslashes before user define characters in a string use addcslashes() function.




$string is a PHP string.


$string="Ram's son goes to his school every morning.";
echo "Old string is : $string <br>";  // it will not work in database query as data
echo "New String is :$new_string";  // it will not give any error in database query


addslashes() function in php


Leave a Reply

    Waiting for your comments