PHP | stripslashes() Function

The stripslashes() function is a built-in function in PHP. This function removes backslashes in a string.
Syntax:

stripslashes(string)

Parameter: This function accepts only one parameter as shown in the above syntax. It is described below:

  • string: This is the only parameter required which specifies the string on which the function will operate.

Return Values: This function returns a string with backslashes stripped off.



Examples:

Input : "Geeks for\ Geeks"
Output : Geeks for Geeks

Input : "A\ Computer \Science \Portal"
Output : A Computer Science Portal

Below programs illustrate the stripslashes() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
    //code
    $str = "Geeks for\ Geeks";
    echo stripslashes($str);
?>

chevron_right


Output:

Geeks for Geeks

Program 2: In this program we will see the array implementation of stripslashes() function. stripslashes() is not recursive. In order to apply this function to an array, a recursive function is required.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
function stripslashes_arr($value)
{
    $value = is_array($value) ?
                array_map('stripslashes_arr', $value) :
                stripslashes($value);
  
    return $value;
}
  
  
$array = array("Gee\\ks ", "fo\\r", " \\Geeks");
$array = stripslashes_arr($array);
  
  
print_r($array);
?>

chevron_right


Output:

Array
(
    [0] => Geeks 
    [1] => for
    [2] =>  Geeks
)

Reference:
http://php.net/manual/en/function.stripslashes.php



My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.