By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,175 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

Need to remove escape (backslash)

cassbiz
100+
P: 202
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.



Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if($_POST['edit'])  {
  3.         $filename  =  $_POST['file'];
  4.         $handle  =  fopen($filename,  "r");
  5.         $contents  =  fread($handle,  filesize($filename));
  6.         echo  "<form  method=\"post\"  action=\"coupon_edit.php?area=edit\">
  7.          <strong>$filename</strong><br>
  8.          <input  type=\"hidden\"  name=\"file\"  value=\"$filename\">
  9.          <textarea  name=\"content\"  cols=\"60\"  rows=\"20\">".$contents."</textarea><br>
  10.           <input  type=\"submit\"  name=\"update\"  value=\"Update\">
  11.                                 </form>";
  12.         fclose($handle);
  13. }  elseif($_POST['update'])  {
  14.         $filename  =  $_POST['file'];       
  15.         if(is_writable($filename))  {
  16.                 $handle  =  fopen($filename,  "w+");
  17.                 fwrite($handle,  $_POST['content']);
  18.                 fclose($handle);               
  19.                 echo  "File:  <strong>".  $filename  .  "</strong>  edited  successfully.<br><a  href=\"$PHP_SELF\">Edit    
  20. More  Files</a>";
  21.         }  else  {
  22.                 echo  "Error!  <strong>".  $filename  .  "</strong>  File  may  not  be  writable.";
  23.         }      
  24. }  else  {
  25.         echo  "<form  method=\"post\"  action=\"$PHP_SELF\">
  26.                                         File:  <input  type=\"text\"  name=\"file\"><br>
  27.                                         <input  type=\"submit\"  name=\"edit\"  value=\"Edit\">
  28.                                 </form>";
  29. }
  30. ?>  
  31.  
The output for the file is:

Expand|Select|Wrap|Line Numbers
  1. @sc_discount_logic = (\"1009||||5%\", \"1500||||5.00\");
  2.  
What I need is:

Expand|Select|Wrap|Line Numbers
  1. @sc_discount_logic = ("1009||||5%", "1500||||5.00");
  2.  
I have tried stripslashes but the output is being used by a perl file.

Thanks in advance
May 7 '07 #1
Share this Question
Share on Google+
5 Replies


ak1dnar
Expert 100+
P: 1,584
try like this for echo the form elements.

[PHP]echo '<form method="post" action="coupon_edit.php?area=edit">';[/PHP]
May 8 '07 #2

pbmods
Expert 5K+
P: 5,821
This doesn't directly relate to your problem, but you might like this.

[PHP]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>";[/PHP]
can be rewritten as:

[PHP]
echo <<<EOF
<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>
EOF;
[/PHP]

*http://www.php.net/manual/en/languag...syntax.heredoc
May 8 '07 #3

Motoma
Expert 2.5K+
P: 3,235
There is a stripslashes() function that removes slashes from user input.
May 9 '07 #4

cassbiz
100+
P: 202
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

Expand|Select|Wrap|Line Numbers
  1. @sc_discount_logic = ("1009||||5%", "1500||||5.00");
  2.  
and it is

Expand|Select|Wrap|Line Numbers
  1. ".@sc_discount_logic = ("1009||||5%", "1500||||5.00");."
  2.  

So I changed the string from

Expand|Select|Wrap|Line Numbers
  1. <textarea  name="content"  cols="60"  ows="20">".$contents."</textarea><br>
  2.  
to

Expand|Select|Wrap|Line Numbers
  1. echo  <<<EOF
  2.  
  3. <form  method="post"  action="coupon_edit1.php?area=edit">
  4. <strong>$filename</strong><br>
  5. <input  type="hidden"  name="file"  value="$filename">
  6. <textarea  name="content"  cols="60"  rows="20">
  7. EOF;
  8.  
  9. echo $contents;
  10.  
  11. echo <<<EOF
  12.  
  13. </textarea><br>
  14. <input  type="submit"  name="update"  value="Update">
  15. </form>
  16.  
  17. EOF;
  18.  
and though the file is writing correctly, the error message "Error! File may not be writable." is coming up.

Any hints as to why?
May 9 '07 #5

cassbiz
100+
P: 202
I figured it out.

I thank all of you

-- again --
May 9 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.