addslashes() function in PHP || PHP adslashes function
×


addslashes() function in php

0 560

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.


Syntax:

addslashes($string);

here,

$string is a PHP string.


Example:

<?php
$string="Ram's son goes to his school every morning.";
$new_string=addslashes($string);
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
?>

Output:



Share:


Leave a Reply


Comments
    Waiting for your comments