moving companies : Computers : Programming : Languages : PHP : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 3 people (100%) answered Yes
Recently 3 of 3 people (100%) answered Yes

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