PHP stripcslashes() Function

Definition
In PHP, stripcslashes() turns C-style escape sequences back into real characters.
It undoes addcslashes() and understands codes such as \n, \t, \xhh, and octal values.
Syntax
Call stripcslashes() with the values you need. Start with this line.
$plain = stripcslashes($escaped);
| Call | What it does |
|---|
stripcslashes('Hello\nWorld') | Turns \n into a real new line. |
stripcslashes('\x41\x42') | Returns "AB". |
It recognizes \n, \t, \r, \a, \v, \b, \f, \\, hex like \x41, and octal like \101.
Library declarations
stripcslashes(string $string): string
Parameters
| Parameter | Description |
|---|
| string | Required. The string that contains escape sequences. |
Return Value
| Return Value | Description |
|---|
| string | The string with escape sequences converted to real characters. |
PHP Examples
Example 1 — Turn \n into a New Line
A single-quoted string keeps the backslash and the letter n.
<?php
$text = 'Hello\nWorld';
echo stripcslashes($text), PHP_EOL;
How It Works
- Use single quotes. The text holds a backslash and an
n. - Call stripcslashes(). It reads
\n as a new line. - Get two lines. The output is split in the middle.
- Print with PHP_EOL. A final line break is added.
Example 2 — Hex and Octal Codes
Character codes become letters.
<?php
echo stripcslashes('\x41\x42\103'), PHP_EOL;
How It Works
- \x41 is hex. It is the letter
A. - \x42 is hex too. It is the letter
B. - \103 is octal. It is the letter
C. - All three are joined. The result is
ABC.
Frequently Asked Questions
stripcslashes() converts C-style escape sequences like \n, \t, \x41, and \101 back into the characters they stand for.
stripcslashes(string $string): string. Pass the escaped text and it returns the unescaped result.
stripslashes() only removes backslashes. stripcslashes() also understands C-style codes such as \n and \x41.
addcslashes(). It adds C-style escapes to the characters you choose.
In a double-quoted PHP string, \n is already a real new line. Use single quotes to keep the backslash and n as plain text.
Next: stripos()
stripos() finds the position of the first match of a substring, ignoring letter case.
stripos() tutorial →About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful