PHP function stripcslashes() – Un-quote string quoted with addcslashes()

stripcslashes() converts C-style escape sequences (\, \a, \b, \f, \n, \r, \t, \v, and \x hh hex and \ ooo octal character escape sequences) to their literal equivalents. Additionally, it strips the backslash from escape sequences that it doesn’t recognize. You can specify ranges of characters by separating them by two periods; for example, to un-escape characters between a and q, use “a..q”. Multiple characters and ranges can be specified in characters. The stripcslashes() function is the inverse of addcslashes().

Syntax:

stripcslashes(string $string): string

To remove backslashes without performing conversions:

stripslashes() 

To add escape sequences to a string:

addslashes() 
addcslashes()

Parameters

Parameter Description
string The string to be unescaped.

Return Values

Returns the unescaped string.

Examples

Example 1:

<?php
var_dump(stripcslashes('I\'d have a coffee.\nNot a problem.') === "I'd have a coffee. Not a problem."); // true
?>

Final Thoughts

The addcslashes function returns the text argument after escaping characters in the style of the C programming language. Briefly, this means special characters are replaced with codes, such as \n replacing a newline character, and other characters outside ASCII 32-126 are replaced with backslash octal codes.

Related Post