Hi,
i've got a bug in some code i've written and i'm not sure if it's casued by php or html.
i've created 3 files that edit and display 'news updates' (kept in a text file) and that has an authentication script in it aswell. (see all files printed out below)
my problem is this - when the news file is displayed in the form of a text area (re. forms) for editing, the first line is always blank. some how the process remembers that the first line is blank and so if the news file's opened, say 10 times for editing it will have 10 blanks lines before the news info is displayed. when i open the text file, no blank lines are in there and more importantly when the new file is displayed on the 'news' page (not in a text area) it also doesn't have any leading blank lines. so it seems it's just when the file is opened into a text area and not at any other time.
an easy option is just to delete the blank lines when it's in edit mode but as this is for someone else, i want to make it as straight forward as possible.
is there an easy solution in html or php, maybe some code for detecting blanks lines and removing them before it's displayed - this is where my lack of exeperience kicks in!! also it just seem squite an intriging little bug to sort out.
===display and password page -
no problem with this one =====
<?php
$filename = "file.txt";
$whattoread = @fopen($filename, "r") or die("Couldn't create file.");
$file_contents = fread($whattoread, filesize($filename));
$msg = "$file_contents";
fclose($whattoread);
?>
<html>
<head><title>News Update - Admin</title>
<link rel="STYLESHEET" type="text/css" href="rej.css" /></head>
<body>
<table border="1" align="center">
<tr><td align="top">
<? echo "$msg" ?></p>
</td></tr>
<tr><td align="center">
<form action="rej_edit.php" method="post">
Username:<br>
<input type="text" name="usr"/><br>
Password:<br>
<input type="password" name="pwd"/><br><br>
<input type="submit" value="Login..." />
</form>
</td></tr>
</table>
</body>
</html>
==== edit page - the error occurs here, when the text file is displayed in the textarea ===
<?php
if ($usr != "login" || $pwd != "password")
{
header( 'Location: xxxxxx' );
}
$filename = "file.txt";
$whattoread = @fopen($filename, "r") or die("Couldn't create file.");
$file_contents = fread($whattoread, filesize($filename));
$msg = "$file_contents";
fclose($whattoread);
?>
<html>
<head><title>News Update - Admin</title>
<link rel="STYLESHEET" type="text/css" href="rej.css" /></head>
<body>
<table border="1" align="center">
<tr><td>
Put note about formating tags to use here ...
</td></tr>
<form method="post" action="rej_write.php">
<tr><td>
<textarea name="newstring" rows="20" cols="55">
<?echo "$msg" ?>
</textarea>
</td></tr>
<tr><td align="center">
<input type="submit" name="submit" value="confirm">
</td></tr>
</form>
</table>
</body>
</html>
==== text file - no leading blanks appear in it =======
<b>news1</b></br>
<i>19/11/03</i></br>
today something happened</br></br>
<b>news2</b></br>
<i>19/11/03</i></br>
today something else happened</br></br>
<b>news3</b></br>
<i>19/11/03</i></br>
and something else too</br></br>
<b>news4</b></br>
<i>19/11/03</i></br>
only joking!!</br></br>
<b>news5</b></br>
<i>24/11/03</i></br>
still only joking!!</br></br>
well, i tried to make this as short as poss, but if you haven't fallen as sleep before you get to this bit and you have any advice - it would be greatly appreciated - thanks,
mat