Why we use PHP addcslashes() Function?

Why we use PHP addcslashes() Function?

The addcslashes() function is a built-in function in PHP. The addcslashes() function is used to add backslashes before some specified characters in a given string.

Syntax of addcslashes Function in  PHP

string addcslashes($string, $characters)

Parameters: This function accepts two parameters as shown in the above syntax and are described below;

$string: The string in which we want to add backslashes before some specified characters.

$characters: This parameter specifies a character or sequence of characters which we want to escape in the input string and this can be achieved by adding the backslashes before them.

We can specify a range of characters as ‘a..j’ or ‘a..y’ etc. Before two dots, it is the start character of the range followed by two dots and the ending character can be written at the end of two dots.

Some characters are predefined escape sequences and have some special meaning like a,b,n,t, etc, so use the characters carefully. Otherwise, Maybe you fail to get the desired result.

Below programs illustrate the addcslashes() function in PHP:

Example Program of PHP addcslashes() Function

Let’s see the Example Program of PHP addcslashes() Function.

Example Program of PHP addcslashes() Function

Output

T4Tutor\i\als

Add a Comment