How do I stripslashes from text?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
firstbat
Forum Newbie
Posts: 1
Joined: Sun Jan 25, 2009 5:16 pm

How do I stripslashes from text?

Post 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);   
?>
Deuce
Forum Newbie
Posts: 12
Joined: Sun Jan 25, 2009 5:23 pm

Re: How do I stripslashes from text?

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: How do I stripslashes from text?

Post by Chris Corbyn »

But if you can do so, disable magic_quotes_gpc in php.ini. It's a terrible "feature".
Post Reply