PHP addcslashes() function

The addcslashes() function : add backslashes in front of the specified characters in a string.

Syntax

addcslashes ( string $string , string $charlist ) : string

Parameters

Parameter Name Descrption
$string Required, The string to be escaped
$charlist

Optional, A list of characters for escaped

Cscape Characters Converted to
0 (NULL) \0
r (carriage return) \r
n (newline) \n
t (tab) \t
v (vertical tab) \v
f (form feed) \f

Return Value

Returns the escaped string

addcslashes() examples

echo addcslashes("Test String","S");
//Test \String

$string = "addcslashes String Example in PHP";
echo addcslashes($string,'S');
//addcslashes \String Example in PHP

echo addcslashes($string,'s');
//addc\sla\she\s String Example in PHP

Related Functions