Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts

    writting .php to disk problem (\") - don't want slash

    I have only recently begun to look at php (approx 3 hours now). I've figured out the majority of the basics. I have a script that reads a text document into a textarea then when you submit it saves the changes. The problem is, whenever there is a quote sign (single or double) it automatically gets escaped (\ gets added). How can I make it so it doesn't do this?

    PHP Code:
    <?

    $filename 
    "file.php";
    $fp fopen ($filename"rw");

    echo 
    "<form method=post action=write.php>\n";

    echo 
    "<textarea id='txt' rows='8' cols='80' name='content'>\n";


    $content fread ($fpfilesize ($filename)); 
    echo 
    $content;

    echo 
    "</textarea><br><br>";

    fclose ($fp);

    echo 
    "<input type=submit value=Submit>\n";

    echo 
    "</form>";

    ?>
    write.php:

    PHP Code:
    <?

    $filename 
    "file.php";

    $fp fopen ($filename"w");

    if (!
    fwrite($fpurldecode($_POST['content']))) {
       echo 
    "Could Not Write to file";
       exit;
    }

    echo 
    "Information Written Successfully";
    echo 
    "<script language='javascript'>location.replace('edit.php');</script>";

    fclose($fp);

    ?>

    I figure you need to use serialize() or urldecode(), but not sure how to use them. Any help/advice would be greatly appreciated. Thanks in advance.

    -x_goose_x

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    $content fread ($fpfilesize ($filename)); 
    $content stripslashes($content);
    echo 
    $content;

    echo 
    "</textarea><br><br>"

  • #3
    Registered User
    Join Date
    Feb 2003
    Location
    Berkshire, UK
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    http://uk.php.net/manual/en/function.stripslashes.php

    string stripslashes ( string str)
    take a look at the link for more info

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually as soon as I got his/her response I searched php.net. I figured it would be easier to remove the slashes before writing it to disk, so I changed:
    if (!fwrite($fp, urldecode($_POST['content']))) {
    to:
    if (!fwrite($fp, urldecode(stripslashes($_POST['content'])))) {
    and it works fine. Thanks for the help.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •