Need to remove escape (backslash)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cassbiz
    New Member
    • Oct 2006
    • 202

    Need to remove escape (backslash)

    I am using the below script to open a file and rewrite it. When it rewrites it adds backslashes because magic_quotes_on on any text that contains a single or double quote.



    Code:
    <?php
    if($_POST['edit'])  {
            $filename  =  $_POST['file'];
            $handle  =  fopen($filename,  "r");
            $contents  =  fread($handle,  filesize($filename));
            echo  "<form  method=\"post\"  action=\"coupon_edit.php?area=edit\">
             <strong>$filename</strong><br>
             <input  type=\"hidden\"  name=\"file\"  value=\"$filename\">
             <textarea  name=\"content\"  cols=\"60\"  rows=\"20\">".$contents."</textarea><br>
              <input  type=\"submit\"  name=\"update\"  value=\"Update\">
                                    </form>";
            fclose($handle);
    }  elseif($_POST['update'])  {
            $filename  =  $_POST['file'];       
            if(is_writable($filename))  {
                    $handle  =  fopen($filename,  "w+");
                    fwrite($handle,  $_POST['content']);
                    fclose($handle);               
                    echo  "File:  <strong>".  $filename  .  "</strong>  edited  successfully.<br><a  href=\"$PHP_SELF\">Edit    
    More  Files</a>";
            }  else  {
                    echo  "Error!  <strong>".  $filename  .  "</strong>  File  may  not  be  writable.";
            }      
    }  else  {
            echo  "<form  method=\"post\"  action=\"$PHP_SELF\">
                                            File:  <input  type=\"text\"  name=\"file\"><br>
                                            <input  type=\"submit\"  name=\"edit\"  value=\"Edit\">
                                    </form>";
    }
    ?>
    The output for the file is:

    Code:
    @sc_discount_logic = (\"1009||||5%\", \"1500||||5.00\");
    What I need is:

    Code:
    @sc_discount_logic = ("1009||||5%", "1500||||5.00");
    I have tried stripslashes but the output is being used by a perl file.

    Thanks in advance
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    try like this for echo the form elements.

    [PHP]echo '<form method="post" action="coupon_ edit.php?area=e dit">';[/PHP]

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      This doesn't directly relate to your problem, but you might like this.

      Originally posted by cassbiz
      [PHP]echo "<form method=\"post\" action=\"coupon _edit.php?area= edit\">
      <strong>$filena me</strong><br>
      <input type=\"hidden\" name=\"file\" value=\"$filena me\">
      <textarea name=\"content\ " cols=\"60\" rows=\"20\">".$ contents."</textarea><br>
      <input type=\"submit\" name=\"update\" value=\"Update\ ">
      </form>";[/PHP]
      can be rewritten as:

      [PHP]
      echo <<<EOF
      <form method="post" action="coupon_ edit.php?area=e dit">
      <strong>$filena me</strong><br>
      <input type="hidden" name="file" value="$filenam e">
      <textarea name="content" cols="60" rows="20">$cont ents</textarea><br>
      <input type="submit" name="update" value="Update">
      </form>
      EOF;
      [/PHP]

      *http://www.php.net/manual/en/languag...syntax.heredoc

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        There is a stripslashes() function that removes slashes from user input.

        Comment

        • cassbiz
          New Member
          • Oct 2006
          • 202

          #5
          Originally posted by Motoma
          There is a stripslashes() function that removes slashes from user input.
          OK ! Great ! the stripslashes worked.

          Now I have another issue :(

          the output should be

          Code:
          @sc_discount_logic = ("1009||||5%", "1500||||5.00");
          and it is

          Code:
          ".@sc_discount_logic = ("1009||||5%", "1500||||5.00");."

          So I changed the string from

          Code:
          <textarea  name="content"  cols="60"  ows="20">".$contents."</textarea><br>
          to

          Code:
          echo  <<<EOF
          
          <form  method="post"  action="coupon_edit1.php?area=edit">
          <strong>$filename</strong><br>
          <input  type="hidden"  name="file"  value="$filename">
          <textarea  name="content"  cols="60"  rows="20">
          EOF;
          
          echo $contents;
          
          echo <<<EOF
          
          </textarea><br>
          <input  type="submit"  name="update"  value="Update">
          </form>
          
          EOF;
          and though the file is writing correctly, the error message "Error! File may not be writable." is coming up.

          Any hints as to why?

          Comment

          • cassbiz
            New Member
            • Oct 2006
            • 202

            #6
            I figured it out.

            I thank all of you

            -- again --

            Comment

            Working...