fwrite is adding extra text, why? and where is it coming from????
| From: | Joey Garcia | Date: | Mon, 22 Jan 2001 19:41:55 +0000 |
| Subject: | fwrite is adding extra text, why? and where is it coming from???? | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-5143@lists.php.net to get a copy of this message | ||
I an using the fwrite command to show how it works but it is writing extra
data. For example, I have a Form text box that prompts for a new string of
data then on submit it writes this to the text file and for just a test I
wrote "this is a test" and I got the text below. I don't understand why??
this is a testy>
</html>
/ / DTD HTML
I put a space between the two slashes otherwise Outlook puts a "file:" in
front of it like this //
Here is a snippet of my code for performing the write, there is enough here
show you my approach.
print "<form name=myform action=fileio.php>";
$filename="c:\\Program Files\\Apache Group\\Apache\\htdocs\\testfile.txt";
$fp=fopen($filename, "r+");
if (!empty($newText)){
fwrite($fp, $newText);
fclose($fp);
$fp=fopen($filename, "r+");
$contents=fread($fp, filesize($filename));
}else {
$contents=fread($fp, filesize($filename));
}
fclose($fp);
print "The content of the file is:
<p><b>".nl2br($contents)."</b>";
print "<br><p>Enter some text to write to the file.<br>";
print "<input type=text name=newText size=30><br>";
print "<input type=submit value='write text'>";
Note: I know I probably shouldn't write to a file and then reopen it, but I
am trying to demonstrate that I am actually reading and writing so I didn't
want to cheat and say I was actually reading it when I wasn't.
The resulting text always has the "testy>
</html>
// DTD HTML " text appended after it. (???????)