Log in

View Full Version : Removing PHP-generated backslashes



molendijk
07-23-2014, 10:13 PM
Hello you PHP-gurus,
I've put the following code on a page:

<?php
$fn = "file.html";
$file = fopen($fn, "r+");
$size = filesize($fn);
if($_POST['addition']) fwrite($file, $_POST['addition']);
$html = fread($file, $size);
fclose($file);
?>

<form name="myform" action="<?=$PHP_SELF?>" method="post" target="frame">
<div id="the_content" contenteditable="true" >
<?=$html?>
</div><br>
<input type="text" name="addition" id="addition" style="display:none">
</form>

<button onmouseover="document.getElementById('addition').focus();document.getElementById('addition').value=document.getElementById('the_content').innerHTML" onmouseup="document.myform.submit();">Save</button>

<iframe name="frame" style="display: none"></iframe>

The code works fine. Whatever I write in the contenteditable div is saved and stored on the server.
My problem is the behavior of one of my servers. Whenever I put something between quotes in the contenteditable div, it (the server) ads a backslash. I've googled around and tried all kinds of suggestions but without succes. Does anyone have a solution for this particular case?
Thanks.

fastsol1
07-23-2014, 10:29 PM
stripslashes()

molendijk
07-23-2014, 10:35 PM
Thanks.
Yes, I know, but I don't know how to use it in my code, in this particular case.

fastsol1
07-23-2014, 10:49 PM
stripslashes($html)

molendijk
07-23-2014, 11:00 PM
I already tried that in my php-code. No succes. Where in my code should I put it?
Thanks.

jscheuer1
07-24-2014, 02:20 AM
<?php
$fn = "file.html";
$file = fopen($fn, "r+");
$size = filesize($fn);
if($_POST['addition']) fwrite($file, $_POST['addition']);
$html = fread($file, $size);
$html = stripslashes($html);
fclose($file);
?>

Either that, or try turning off magic quotes on the problematic server.

molendijk
07-24-2014, 09:18 AM
Thanks John, that did it!