PHP stripcslashes() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
String

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.

PHP
$plain = stripcslashes($escaped);
CallWhat 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
PHP
stripcslashes(string $string): string

Parameters

ParameterDescription
stringRequired. The string that contains escape sequences.

Return Value

Return ValueDescription
stringThe 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
<?php
$text = 'Hello\nWorld';

echo stripcslashes($text), PHP_EOL;

How It Works

  1. Use single quotes. The text holds a backslash and an n.
  2. Call stripcslashes(). It reads \n as a new line.
  3. Get two lines. The output is split in the middle.
  4. Print with PHP_EOL. A final line break is added.

Example 2 — Hex and Octal Codes

Character codes become letters.

PHP
<?php
echo stripcslashes('\x41\x42\103'), PHP_EOL;

How It Works

  1. \x41 is hex. It is the letter A.
  2. \x42 is hex too. It is the letter B.
  3. \103 is octal. It is the letter C.
  4. All three are joined. The result is ABC.

Example 3 — Round Trip with addcslashes()

Escape a tab, then bring it back.

PHP
<?php
$escaped = addcslashes("A\tB", "\t");
echo $escaped, PHP_EOL;

$plain = stripcslashes($escaped);
echo bin2hex($plain), PHP_EOL;

How It Works

  1. Escape the tab. addcslashes() writes it as \t.
  2. Print the escaped text. You can see the backslash.
  3. Call stripcslashes(). The tab character comes back.
  4. Check with bin2hex(). 09 is the tab byte.

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

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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