Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

addslashes

Adds a backslash before quotes.

Syntax

addslashes(string $string): string

Parameters

ParameterTypeDescription
$stringstringThe input string.

Return value

stringThe string with `'`, `"`, `\` and the null byte escaped.

Examples

A quote inside a string:

<?php
 
echo addslashes("It's a \"quote\"");

Output:

It\'s a \"quote\"

Notes

The function does not protect against SQL injection — use prepared statements for queries. To put data into JavaScript use json_encode().

See also

In the tutorial

  • Security — The basics of PHP site security — XSS and escaping, SQL injection, password hashing, CSRF tokens and validating input.

Thanks for reading!

Donate to the site — we work hard for you.