...

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



x_goose_x
02-19-2003, 12:26 AM
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?



<?

$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 ($fp, filesize ($filename));
echo $content;

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

fclose ($fp);

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

echo "</form>";

?>


write.php:



<?

$filename = "file.php";

$fp = fopen ($filename, "w");

if (!fwrite($fp, urldecode($_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

Nightfire
02-19-2003, 01:11 AM
$content = fread ($fp, filesize ($filename));
$content = stripslashes($content);
echo $content;

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

thox
02-19-2003, 01:37 PM
http://uk.php.net/manual/en/function.stripslashes.php


string stripslashes ( string str)

take a look at the link for more info

x_goose_x
02-19-2003, 04:18 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum