stripslashes

(PHP 4, PHP 5)

stripslashesUn-quotes a quoted string

Description

string stripslashes ( string $str )

Un-quotes a quoted string.

Note:

If magic_quotes_sybase is on, no backslashes are stripped off but two apostrophes are replaced by one instead.

An example use of stripslashes() is when the PHP directive magic_quotes_gpc is on (it was on by default before PHP 5.4), and you aren't inserting this data into a place (such as a database) that requires escaping. For example, if you're simply outputting data straight from an HTML form.

Parameters

str

The input string.

Return Values

Returns a string with backslashes stripped off. (\' becomes ' and so on.) Double backslashes (\\) are made into a single backslash (\).

Examples

Example #1 A stripslashes() example

<?php
$str 
"Is your name O\'reilly?";

// Outputs: Is your name O'reilly?
echo stripslashes($str);
?>

Note:

stripslashes() is not recursive. If you want to apply this function to a multi-dimensional array, you need to use a recursive function.

Example #2 Using stripslashes() on an array

<?php
function stripslashes_deep($value)
{
    
$value is_array($value) ?
                
array_map('stripslashes_deep'$value) :
                
stripslashes($value);

    return 
$value;
}

// Example
$array = array("f\\'oo""b\\'ar", array("fo\\'o""b\\'ar"));
$array stripslashes_deep($array);

// Output
print_r($array);
?>

The above example will output:

Array
(
    [0] => f'oo
    [1] => b'ar
    [2] => Array
        (
            [0] => fo'o
            [1] => b'ar
        )

)

See Also

Коментарии

Might I warn readers that they should be vary careful with the use of stripslashes on Japanese text. The shift_jis character set includes a number of two-byte code charcters that contain the hex-value 0x5c (backslash) which will get stripped by this function thus garbling those characters.

What a nightmare!
2003-11-30 23:34:07
http://php5.kiev.ua/manual/ru/function.stripslashes.html
Автор:
in response to crab dot crab at gmail dot com:

$value need not be passed by reference. The 'stripped' value is returned. The passed value is not altered.
2007-01-02 10:31:46
http://php5.kiev.ua/manual/ru/function.stripslashes.html
If you need to remove all slashes from a string, here's a quick hack:

<?php
function stripallslashes($string) {
    while(
strchr($string,'\\')) {
       
$string stripslashes($string);
    }
}
?>

Hope it's usefull , O-Zone
2009-03-19 05:53:43
http://php5.kiev.ua/manual/ru/function.stripslashes.html
Автор:
A replacement that should be safe on utf-8 strings.
<?php
  preg_replace
(array('/\x5C(?!\x5C)/u''/\x5C\x5C/u'), array('','\\'), $s);
?>
2009-03-23 09:26:23
http://php5.kiev.ua/manual/ru/function.stripslashes.html
Hi, 

Here are recursive addslashes / stripslashes functions.
given a string - it will simply add / strip slashes
given an array - it will recursively add / strip slashes from the array and all of it subarrays. 
if the value is not a string or array - it will remain unmodified!

<?php

function add_slashes_recursive$variable )
{
    if ( 
is_string$variable ) )
        return 
addslashes$variable ) ;

    elseif ( 
is_array$variable ) )
        foreach( 
$variable as $i => $value )
           
$variable$i ] = add_slashes_recursive$value ) ;

    return 
$variable ;
}

function 
strip_slashes_recursive$variable )
{
    if ( 
is_string$variable ) )
        return 
stripslashes$variable ) ;
    if ( 
is_array$variable ) )
        foreach( 
$variable as $i => $value )
           
$variable$i ] = strip_slashes_recursive$value ) ;
   
    return 
$variable 
}

?>
2009-05-09 18:50:42
http://php5.kiev.ua/manual/ru/function.stripslashes.html
Sometimes for some reason is happens that PHP or Javascript or some naughty insert a lot of  backslash. Ordinary function does not notice that. Therefore, it is necessary that the bit "inflate":

<?php
function removeslashes($string)
{
   
$string=implode("",explode("\\",$string));
    return 
stripslashes(trim($string));
}

/* Example */

$text="My dog don\\\\\\\\\\\\\\\\'t like the postman!";
echo 
removeslashes($text);
?>

RESULT: My dog don't like the postman!

This flick has served me wery well, because I had this problem before.
2014-03-04 17:29:45
http://php5.kiev.ua/manual/ru/function.stripslashes.html

    Поддержать сайт на родительском проекте КГБ