PHP addslashes help

Discussion in 'PHP' started by Tropica, Nov 24, 2007.

  1. #1
    Hi

    I have a textarea that writes to a .txt file, but it adds / next to " or '

    I have been reading up on addslashes, but I can't implement it right :(

    <?php
    
    if (isset( $_POST ))
       $postArray = &$_POST ;			// 4.1.0 or later
    else
       $postArray = &$HTTP_POST_VARS ;	// prior to 4.1.0
    
    
    $fname="post.txt";
    
    
    $nfile = fopen($fname, "w");
    
    
    if($nfile != false)
    {
    	foreach ($postArray as $sForm => $value )
    	{
    		fwrite($nfile, $value);
    	}
    
    
    	fclose($nfile);
    }	
    
    ?>
    PHP:
    Thats my php code in the post.php and here is my form:

       
    <form action="post.php" method="post">
    
    <textarea name="post" id="post"><? include ('post.txt') ?></textarea>
     <script language="JavaScript">
      generate_wysiwyg('post');
    </script> 
    <br />
    <br />
    
    <input type="submit" value="Confirm Changes">
    </form>
    PHP:
    If anyone could help I would really appreciate it :)
     
    Tropica, Nov 24, 2007 IP
  2. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Probably your Webserver is escaping the quote characters automatically. You don't need to use addslashes in your case, you need stripslashes ;)
    Try this:
    
    if (get_magic_quotes_gpc())
    {
    	fwrite ($nfile, stripslashes($value));
    }
    else fwrite ($nfile, $value);
    
    Code (markup):
    Depending on who is submitting the form, if it isn't you, i would recommend checking the user input anyways...
     
    hogan_h, Nov 24, 2007 IP
    Tropica likes this.
  3. Tropica

    Tropica Notable Member

    Messages:
    2,431
    Likes Received:
    128
    Best Answers:
    0
    Trophy Points:
    230
    #3
    hey thanks :)

    it is for a user input, where about would I place that code in my script?

    Cheers!
     
    Tropica, Nov 24, 2007 IP
  4. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #4
    you put that inside your foreach statement

    if($nfile != false)
    {
    foreach ($postArray as $sForm => $value )
    {
    if (get_magic_quotes_gpc())
    {
    fwrite ($nfile, stripslashes($value));
    }
    else
    {
    fwrite ($nfile, $value);
    }

    fclose($nfile);
    }
     
    serialCoder, Nov 24, 2007 IP
    Tropica likes this.
  5. Tropica

    Tropica Notable Member

    Messages:
    2,431
    Likes Received:
    128
    Best Answers:
    0
    Trophy Points:
    230
    #5
    that got it! thanks!!!
     
    Tropica, Nov 24, 2007 IP