Entry
What is the best code to remove \ from user input when it is saved to file, or used in a variable?
Nov 30th, 2002 21:14
Philip Olson, Mark Kesley, Paul Stevens,
Most likely you are seeing these because of the PHP directive
magic_quotes_gpc. You may read about it in the PHP manual here:
http://www.php.net/manual/en/ref.info.php#ini.magic-quotes-gpc
An excerpt from the manual:
Sets the magic_quotes state for GPC (Get/Post/Cookie) operations.
When magic_quotes are on, all ' (single-quote), " (double quote),
\ (backslash) and NUL's are escaped with a backslash automatically.
The magic_quotes_gpc directive defaults to ON. This directive
essentially runs addslashes() on your Get, Post, and Cookie data
which is useful for entering in data into a database. But you
aren't always going to use a database so for example if you want
to remove the escaped backslashes you can use stripslashes():
$var = stripslashes($_POST['var']);
print $var;
See also: http://www.php.net/stripslashes
http://www.php.net/addslashes