The stripslashes() function is a built-in function in PHP. This function removes backslashes in a string.
Syntax:
php
Output:
php
Output:
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.
Input : "Geeks for\ Geeks" Output : Geeks for Geeks Input : "A\ Computer \Science \Portal" Output : A Computer Science PortalBelow programs illustrate the stripslashes() function in PHP: Program 1:
<?php
//code
$str = "Geeks for\ Geeks";
echo stripslashes($str);
?>
Geeks for GeeksProgram 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.
<?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);
?>
Array
(
[0] => Geeks
[1] => for
[2] => Geeks
)
Reference:
https://www.php.net/manual/en/function.stripslashes.php