August 19th, 2000, 03:37 PM
-
I'm trying to write to a file, then write the contents of that file into html. The recieving file "data.txt" is recieving one line of input, and the html prints infinitely (well, up to 175 k at which I pulled the plug) Here's the code.
<html>
<head>
<title>write test</title>
</head>
<body bgcolor="green">
<p>
Here's some text in the html, later
we'll see what comes from the php
</p>
<?
// open file for writing
$myFile = fopen("data.txt", "w");
// make sure file opened
if(!($myFile))
{
print("file open no can do boss");
exit;
}
for($index=0; $index<10; $index++);
{
//write a line to file
fputs($myFile, "line $index n");
}
while(!(feof($myFile)))
{
// read from the file
//$myLine = fgetss($myFile, 255);
//print("$myLine <br>n");
print('Hell, say anything! ');
}
// close file
fclose($myFile);
?>
</body></html>
--
Robert Link
August 19th, 2000, 05:19 PM
-
Since you're always putting, it has no EOF.
But if you're reading from somewhere else... Then check the EOF of the source file.
------------------
Eduardo Teixeira Cardoso
PHP Programmer from Brazil
idnotfound@vircio.com.br
August 19th, 2000, 06:06 PM
-
for($index=0; $index<10; $index++);
{
//write a line to file
fputs($myFile, "line $index n");
}
$myFile is still open when you get here, for writing. You need to close it before you do the next bit...
eg.
fclose($myFile);
$myFile=fopen("data.txt","r");
while(!(feof($myFile)))
{
// read from the file
//$myLine = fgetss($myFile, 255);
//print("$myLine <br>n");
print('Hell, say anything! ');
}
// close file
Hope that helps,
Kelv
------------------
------------------------
Kelv (29359814)
http://www.lohost.com
Low cost high uptime
for your sites.
August 19th, 2000, 06:38 PM
-
Kelv and Eduardo, thanks! Closing and reopening the file did the trick.
--
Robert Link