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>
.txt include question.
Moderator: General Moderators
Re: .txt include question.
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.
do I put the strip slashes on the page that has the include?
Re: .txt include question.
Yes, wherever you're displaying the file contents in the include.
Re: .txt include question.
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?
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.
wait, shouldn't it be,echo stripslashes("admin/news.txt");
stripslashes($info);
Re: .txt include question.
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
<?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.
Yes, it should be
Code: Select all
<?php
echo stripslashes($info);
?>