Forum Moderators: coopster

Message Too Old, No Replies

the removal of \ in files

me again

         

quozt

2:24 pm on Apr 12, 2004 (gmt 0)

10+ Year Member



at the moment im working on dynamic file creation which is going well apart from when i add HTML code to the page

if (isset ($_POST['submit']))

{
$fp = fopen("../../header.htm", "w" ) or die("Couldn't open $filename");
fwrite( $fp,"
echo '{$_POST['content']}';
" );
fclose( $fp );
print "Writing Main File Complete <br>";

}
else
{
$textarea = file_get_contents("../../header.htm");
}
?>
<h2>Edit Header Page</h2>
<form action="pupilheader.php" method="post">
<p>Desc:<br /> <textarea name="content" cols="100" rows="20"><?echo $textarea;?></textarea></p>
<input type="submit" name="submit" value="Edit The Header" />
</form>

is my code

and that works but when i put html in my code every " and ' gets a \ and it messes up the page... how would i work around this

RonPK

3:27 pm on Apr 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



stripslashes() is your friend.

quozt

4:06 pm on Apr 12, 2004 (gmt 0)

10+ Year Member



where would this be used in the code

lorax

4:14 pm on Apr 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



where? Wherever you output a var that will contain them.

echo stripslashes($string);

quozt

4:39 pm on Apr 12, 2004 (gmt 0)

10+ Year Member



cheers mate

quozt

8:54 pm on Apr 12, 2004 (gmt 0)

10+ Year Member



ok thats working apart from when used in this context

if (isset ($_POST['submit']))

{
$fp = fopen("../../header.htm", "w" ) or die("Couldn't open $filename");
fwrite( $fp,"
echo stripslashes('{$_POST['content']}');
" );
fclose( $fp );
print "Writing Main File Complete <br>";

}
else
{
$textarea = file_get_contents("../../header.htm");
}
?>
<h2>Edit Header Page</h2>
<form action="pupilheader.php" method="post">
<p>Desc:<br /> <textarea name="content" cols="100" rows="20"><?echo $textarea;?></textarea></p>
<input type="submit" name="submit" value="Edit The Header" />
</form>

it doesnt work

WhosAWhata

9:39 pm on Apr 12, 2004 (gmt 0)

10+ Year Member



try
echo stripslashes(htmlspecialchars({$_POST['content']}));

quozt

10:54 pm on Apr 12, 2004 (gmt 0)

10+ Year Member



nope but thanks anyway

RonPK

10:11 am on Apr 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why use echo inside fwrite? That seems like a good way to cause errors to me. If you want to write the contents of $_POST['content'] into a file, try this:
fwrite( $fp, addslashes($_POST['content']));

Use stripslashes when you need to retrieve the contents from the file:
$textarea = file_get_contents("../../header.htm");
$textarea = stripslashes($textarea);