Page 1 of 1

.txt include question.

Posted: Thu Sep 18, 2008 9:31 am
by delveart
I recently built a website that is update-able by the customer. I created a form that writes to a .txt file. The .txt file is then included on the home page, its pretty basic. Every time the site is updated by the customer and they use any of the following punctuation symbols ' " , it adds a / symbol. What I need to know is how to fix my code so that it the punctuation shows up correctly. I am a beginner with this, so assume that I know the least. I am going to set this up in a database when I have time to learn how, but for now I need this to work.

Here is the code from the form page.

<html>
<head>
<title>DLRA News Editor</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../dlra.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body {
background-color: #333333;
}
-->
</style>
<link href="dlraadmin.css" rel="stylesheet" type="text/css">
</head>

<body>
<?php include("updates.php"); ?>
<h1 align="center">News Update</h1>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="top"><?php
$saving = $_REQUEST['saving'];
if ($saving == 1) {
$data = $_POST['data'];
$file = "news.txt";

$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
fwrite($fp, $news) or die("Couldn't write values to file!");

fclose($fp);
echo "Saved to $file successfully!";
}
?>

<form align="center" name="form1" method="post" action="newseditor.php?saving=1">
<textarea name="news" cols="80" rows="20">
<?php
$file = "news.txt";
if (!empty($file)) {
$file = file_get_contents("$file");
echo $file;
}
?>
</textarea>
<br>
<br>
<input type="submit" value="Update News">
</form></td>
</tr>
</table>
<div align="center">
<p><a href="http://www.dlra.net" target="_blank" class="style1"><u>View Update</u>
</a></p>
</div>


</body>
</html>

Re: .txt include question.

Posted: Thu Sep 18, 2008 10:07 am
by Jade
If you do an addslashes() to the info the post, you need to do a stripslashes() to remove them again. Or, if you're encoding them you need to do html_entity_decode to display them properly again.

Re: .txt include question.

Posted: Thu Sep 18, 2008 10:14 am
by delveart
do I put the strip slashes on the page that has the include?

Re: .txt include question.

Posted: Thu Sep 18, 2008 10:15 am
by Jade
Yes, wherever you're displaying the file contents in the include.

Re: .txt include question.

Posted: Thu Sep 18, 2008 10:32 am
by delveart
I successfully got rid of the slashes in the form but I am still getting them in the website content.


Here is my original include.

<?php $file = 'admin/news.txt';
$fp = fopen($file,'r');
$info = fread($fp, filesize($file));
$info = nl2br($info);
echo $info; ?>

Here is the change I made

<?php $file = 'admin/news.txt';
$fp = fopen($file,'r');
$info = fread($fp, filesize($file));
$info = nl2br($info);
echo stripslashes("admin/news.txt");
echo $info; ?>

What am I doing wrong?

Re: .txt include question.

Posted: Thu Sep 18, 2008 10:37 am
by Sindarin
echo stripslashes("admin/news.txt");
wait, shouldn't it be,
stripslashes($info);

Re: .txt include question.

Posted: Thu Sep 18, 2008 10:42 am
by delveart
ha it worked. Thanks for both of your help. Here is what the final include looked like.

<?php $file = 'admin/news.txt';
$fp = fopen($file,'r');
$info = fread($fp, filesize($file));
$info = nl2br($info);
$info = stripslashes($info);

echo $info; ?>

Here is the site

http://www.dlra.net

Thanks a ton

Re: .txt include question.

Posted: Thu Sep 18, 2008 10:43 am
by Jade
Yes, it should be

Code: Select all

 
<?php
echo stripslashes($info);
?>