.txt include question.
Posted: Thu Sep 18, 2008 9:31 am
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>
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>