Page 1 of 1

How do I stripslashes from text?

Posted: Sun Jan 25, 2009 5:20 pm
by firstbat
Hello, new to php and when I have php write to a text file it adds a slash to the text whenever I use ' or ". How can I use stripslashes to my code? I tried a few things and messed it up really good so here is the original code:

Code: Select all

<?php
   $t1 = $_POST['loadtext1'];
   $t2 = $_POST['loadtext2'];
   $t3 = $_POST['loadtext3'];
   $t4 = $_POST['loadtext4'];
   $t5 = $_POST['loadtext5'];
   $t6 = $_POST['loadtext6'];
   $t7 = $_POST['loadtext7'];
   $toSave = "loadtext1=".$t1."&loadtext2=".$t2."&loadtext3=".$t3."&loadtext4=".$t4."&loadtext5=".$t5."&loadtext6=".$t6."&loadtext7=".$t7;
   $fp = fopen("underground/text/text.txt", "w");
   if(fwrite($fp, $toSave)) echo "writing=Ok";
   else echo "writing=Error";
   fclose($fp);   
?>

Re: How do I stripslashes from text?

Posted: Sun Jan 25, 2009 5:26 pm
by Deuce
I'm not the greatest at PHP, but try

Code: Select all

$t1 = stripslashes($t1);
   $t2 = stripslashes($t2);
   $t3 = stripslashes($t3);
   $t4 = stripslashes($t4);
etc...
Add it right after you set the variables with the post.

Re: How do I stripslashes from text?

Posted: Sun Jan 25, 2009 7:26 pm
by Chris Corbyn
But if you can do so, disable magic_quotes_gpc in php.ini. It's a terrible "feature".