PHP addslashes Function


PHP addslashes Function : The string function addslashes adds backslash(\) before each single quote(‘) , double quote(“) in string. Sometimes you need single quotes or double quotes with backslashes. Example (\”) or (\’)


How to use PHP addslashes Function Syntax


addslashes(string)

Input : String.

Retrun : String with backslash.

Single Quotes Example

$string = "Hey Buddy it's John";
$result = addslashes($string);
echo $result;

Try it »


We have a string “Hey Buddy it’s John” in which we will test the function addslashes. We want to add backslash before the “s” character ie “it\’s”. Which will produce the string with backslash as
“Hey Buddy it\’s John.”.
Output :

PHP addslashes Function

PHP addslashes Function

Double Quotes Example

$string = 'Hey Buddy it"s John';
$result = addslashes($string);
echo $result;

Try it »


Advertisements

Add Comment

📖 Read More