HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

addslashes

Description

The addslashes of String for PHP quotes a string with slashes.

A backslash is added before the following characters: single quote ('), double quote ("), backslash (\), and NUL (the NUL byte).

Syntax

addslashes(
    string $string
): string

Parameters

string

The string to be escaped.

Return

Returns the escaped string.

Examples

1 · string · single quote

<?

$string = chr(39). PHP_EOL.
"'". PHP_EOL.
"one o'clock";

$return = addslashes($string);

echo $string. PHP_EOL.
PHP_EOL.
$return;
'
'
one o'clock

\'
\'
one o\'clock

2 · string · double quote

<?

$string = chr(34). PHP_EOL.
'"'. PHP_EOL.
'John said, "The time is now."';

$return = addslashes($string);

echo $string. PHP_EOL.
PHP_EOL.
$return;
"
"
John said, "The time is now."

\"
\"
John said, \"The time is now.\"

3 · string · backslash

<?

$string = chr(92);

$return = addslashes($string);

echo $string. PHP_EOL.
PHP_EOL.
$return;
\

\\

4 · string · NUL

<?

$string = chr(0);

$return = addslashes($string);

echo $string. PHP_EOL.
PHP_EOL.
$return;


\0