PHP 8 reference · String Functions

PHP addslashes() Function

Add a backslash before quotes, backslashes and NUL bytes. Not a safe way to build SQL: use prepared statements.

PHP 8 Since 4.0

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

addslashes(string $string): string

Parameters

ParameterDescription
string The input string.

Return value

The escaped string.

Examples

Escape quotesTry it yourself
<?php
echo addslashes("O'Reilly said \"hi\""), "\n";

Output

O\'Reilly said \"hi\"
Undo it with stripslashes()Try it yourself
<?php
$escaped = addslashes("It's here");
echo $escaped, "\n";
echo stripslashes($escaped), "\n";

Output

It\'s here
It's here

Version history

VersionChange
PHP 4.0Added

Was this page helpful?