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


addslashes() function in php

2116

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:



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments