PHP stripslashes() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
String

Definition

In PHP, stripslashes() removes backslashes added to a string, such as by addslashes().

A double backslash becomes a single backslash, and other backslashes are removed.

Syntax

Call stripslashes() with the values you need. Start with this line.

PHP
$clean = stripslashes($escaped);
CallWhat it does
stripslashes("It\\'s")Returns "It's".
stripslashes('C:\\\\temp')Returns C:\temp.

It only removes backslashes. It does not clean HTML or protect against SQL injection.

Library declarations
PHP
stripslashes(string $string): string

Parameters

ParameterDescription
stringRequired. The string that contains escaping backslashes.

Return Value

Return ValueDescription
stringThe string with backslashes removed.

PHP Examples

Example 1 — Undo addslashes()

Add a backslash, then remove it.

PHP
<?php
$safe = addslashes("It's fine");

echo $safe, PHP_EOL;
echo stripslashes($safe), PHP_EOL;

How It Works

  1. Call addslashes(). It puts a backslash before the quote.
  2. Print the escaped text. You can see \'.
  3. Call stripslashes(). The backslash is removed.
  4. Get the original text. The apostrophe is back to normal.

Example 2 — Double and Single Backslashes

Two backslashes become one, and a lone backslash disappears.

PHP
<?php
echo stripslashes('C:\\\\temp'), PHP_EOL;
echo stripslashes('a\b'), PHP_EOL;

How It Works

  1. Start with two backslashes. In single quotes, four are written for two.
  2. Get one backslash. The path becomes C:\temp.
  3. Try a lone backslash. a\b has one before b.
  4. It is removed. The result is ab.

Example 3 — Clean an Array of Strings

Use array_map() to apply it to every item.

PHP
<?php
$items = ["It\\'s", "Don\\'t"];
$clean = array_map("stripslashes", $items);

echo implode(", ", $clean), PHP_EOL;

How It Works

  1. Start with escaped strings. Each has a backslash before the quote.
  2. Use array_map(). It calls stripslashes() on each one.
  3. Get a new array. The originals are not changed.
  4. Join and print. The quotes look normal again.

Frequently Asked Questions

stripslashes() removes backslashes from a string. It turns \' into ' and a double backslash into a single one.
stripslashes(string $string): string. It takes one string and returns the cleaned version.
addslashes(). It adds a backslash before single quotes, double quotes, backslashes, and NUL bytes.
No. It only removes backslashes. Use prepared statements for databases and htmlspecialchars() when printing user text in HTML.
stripcslashes() also converts C-style codes such as \n and \x41. stripslashes() only removes backslashes.

Next: stristr()

stristr() finds the first occurrence of a substring and returns the rest of the string fro.

stristr() 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