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

stripslashes

Description

The stripslashes of String for PHP un-quotes a quoted string.

Syntax

stripslashes(
    string $string
): string

Parameters

string

The input string.

Return

Returns a string with backslashes stripped off. A backslash with a single quote (\') becomes a single quote ('). A double backslash (\\) becomes a single backslash (\). And so on.

Examples

1 · string · single quote

<?

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

$string = addslashes($addslashesstring);

$return = stripslashes($string);

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

'
'
one o'clock

2 · string · double quote

<?

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

$string = addslashes($addslashesstring);

$return = stripslashes($string);

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

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

3 · string · backslash

<?

$addslashesstring = chr(92);

$string = addslashes($addslashesstring);

$return = stripslashes($string);

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

\

4 · string · NUL

<?

$addslashesstring = chr(0);

$string = addslashes($addslashesstring);

$return = stripslashes($string);

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

5 · recursive

<?

function myfunction($myparameter)
{
    if(is_array($myparameter))
    {
        $myparameter = array_map("myfunction", $myparameter);
    }
    else
    {
        $myparameter = stripslashes($myparameter);
    }
    return $myparameter;
}

$array =
[
    "one o\'clock",
    "two o\'clock",
    [
        "three o\'clock",
        "four o\'clock"
    ]
];

$return = myfunction($array);

print_r($array);
print_r($return);
Array
(
    [0] => one o\'clock
    [1] => two o\'clock
    [2] => Array
        (
            [0] => three o\'clock
            [1] => four o\'clock
        )

)
Array
(
    [0] => one o'clock
    [1] => two o'clock
    [2] => Array
        (
            [0] => three o'clock
            [1] => four o'clock
        )

)