PHP String stripcslashes() Function
The PHP String stripcslashes() function is used to remove backslashes that were used to escape specific characters in a string. It reverses the effects of the addslashes() function. It recognizes C-language characters, including \n, \r, octal, and hexadecimal representations.
Syntax
Below is the syntax of the PHP String stripcslashes() function −
string stripcslashes ( string $string )
Parameters
This function accepts $string parameter which is an input string from which you want to remove backslashes.
Return Value
The stripcslashes() function returns the unescaped string.
PHP Version
First introduced in core PHP 4, the stripcslashes() function continues to function easily in PHP 5, PHP 7, and PHP 8.
Example 1
This program shows the basic usage of how the PHP String stripcslashes() function removes backslashes from the given string.
<?php // Mention the string input here $input = "Hello\\nWorld"; $output = stripcslashes($input); // Print the result echo $output; ?>
Output
Here is the outcome of the following code −
Hello World
Example 2
In the below PHP code we will use the stripcslashes() function and show you how it processes octal escape sequences. Here, '\040' is representing a space.
<?php // Mention the string input here $input = "Tutorials\\040Point"; $output = stripcslashes($input); // Print the result echo $output; ?>
Output
This will generate the below output −
Tutorials Point
Example 3
Now the below code uses stripcslashes() function and shows unescaping hexadecimal representations in a string. Here '\x57' is the hexadecimal representation of 'W'.
<?php // Mention the string here $input = "Hex\\x57orld"; $output = stripcslashes($input); // Print the result echo $output; ?>
Output
This will create the below output −
HexWorld
Example 4
This program we will combine multiple types of escape sequences for unescaping using the stripcslashes() function.
<?php $input = "Line1\\nLine2\\040with\\x21"; $output = stripcslashes($input); echo $output; ?>
Output
Following is the output of the above code −
Line1 Line2 with!