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
Syntax
addslashes(string $string): string
Parameters
| Parameter | Description |
|---|---|
string |
The input string. |
Return value
The escaped string.
Examples
<?php
echo addslashes("O'Reilly said \"hi\""), "\n";
Output
O\'Reilly said \"hi\"
<?php
$escaped = addslashes("It's here");
echo $escaped, "\n";
echo stripslashes($escaped), "\n";
Output
It\'s here It's here
Version history
| Version | Change |
|---|---|
| PHP 4.0 | Added |
Related
htmlspecialchars()· Convert &, <, >, " and ' to HTML entities so user text is shown as text, not run as HTML. The main defence against XSS.- PHP Strings · tutorial
- PHP PDO and Databases · tutorial