📜  stripslash - PHP (1)

📅  最后修改于: 2023-12-03 15:35:10.296000             🧑  作者: Mango

Stripslash - PHP

Stripslash is a built-in PHP function that removes backslashes () from a string. It is commonly used to remove slashes added by magic quotes.

Syntax
stripslashes ( string $str ) : string
Parameters
  • str: The input string.
Return Values

Returns the string with backslashes removed.

Examples
Example 1 - Removing backslashes
$string = "This is a \test";
echo "Original string: " . $string . "<br>";
echo "After removing backslashes: " . stripslashes($string);

Output:

Original string: This is a \test
After removing backslashes: This is a test
Example 2 - Using with form input

When using form input, magic quotes can automatically add backslashes to input fields. Stripslash can be used to remove these backslashes.

$input = $_POST['input_field'];
$clean_input = stripslashes($input);
echo "Cleaned input: " . $clean_input;
Conclusion

Stripslash is a useful built-in function in PHP for removing backslashes from strings. It is commonly used in form input handling to remove slashes added by magic quotes.