Page 2 of 3
Posted: Mon Aug 19, 2002 10:15 pm
by volka
you close the file at every while(list($array) = each($file))-iteration
Posted: Mon Aug 19, 2002 10:18 pm
by Silver_Eclipse
ok so i close it after i finish the while statment and everything in it?
Posted: Mon Aug 19, 2002 10:20 pm
by volka
that in any case.
what does you script look like. I'm a little bit confused about the snippet.
(may be related to the fact that it's 5 am here and I'm only waiting for eDonkey to complete a -of course legal- download)
Posted: Mon Aug 19, 2002 10:23 pm
by Silver_Eclipse
Code: Select all
<?php
$file = file("file.ext");
$filename = "chart.txt";
$fe = fopen ($filename, "a+");
$ff = fread ($fe, 100000);
$hmm = fopen ($filename, "r");
$hmm2 = fread ($hmm, 100000);
$userfile = "users.txt";
$users = fopen ($userfile, "r");
$userread = fread ($users, 100);
$table = "</TABLE>";
$a = 62;
$b = 4320;
while(list($array) = each($file)){
if ($array > $a and $array < $b){
fputs ($fe, $fileї$array], 100000);
}
}
if (file_exists($filename)){
fputs ($fe, $table, 10);
} else {
print "error";
}
if (file_exists($filename)){
include 'style.css';
include 'header.php';
print $hmm2;
end ($file);
} else {
print "error";
}
?>
Posted: Mon Aug 19, 2002 10:37 pm
by volka
wow, gets harder to concentrate from minute to minute
while(list($array) = each($file))
{
if ($array > $a and $array < $b)
fputs ($fe, $file[$array], 100000);
}
the while condition assigns in every iteration a (/the next) line from the array $file to $array - not the index. So (I think) your if-condition is not what you want. Same reason why $file[$array] will probably fail. It tries to access an entry with the index equal to the current line's value. Probably you're looking for something like this
Code: Select all
for ($a=$a+1; $a<count($file) && $a<$b; $a++)
fputs ($fe, $fileї$a], 100000);
if (file_exists($filename))
you're checking this after you've tried to write to a filedescriptor of that file. Your script would have produced a lot of warnings at this point.
can't find any unlink in your script !??!
ahhh...you're opening the same file twice, reading it's contents before you append something. do you want to display the old contents?
Posted: Mon Aug 19, 2002 10:38 pm
by Silver_Eclipse
i removed unlink since it didnt work but i added it at the script because i want it to delete the file after the script runs.
Posted: Mon Aug 19, 2002 10:40 pm
by Silver_Eclipse
and could you explain that script you just showed me some more there are so many $a's and $b's agh (the $a and $b was for the starting line and ending line so it would show everything in between when it sent it to the text file)
Posted: Mon Aug 19, 2002 10:44 pm
by volka
please, first explain what you're trying to achieve.
I can imagine but I'm not quite sure
Posted: Mon Aug 19, 2002 10:46 pm
by Silver_Eclipse
ok first im having it read the array from the $file at teh top and then i have it put that information into the text file, then i want to add </TABLE> tot he end of the text file. and then finally i want it to read back all the info from that text file i had it create.
Posted: Mon Aug 19, 2002 10:52 pm
by volka
so you want to keep only lines 63 to 4319 in the original file and add </table>, right?
what is
if (file_exists($filename)){
include 'style.css';
include 'header.php';
print $hmm2;
end ($file);
} else {
print "error";
}
supposed to do?
Posted: Mon Aug 19, 2002 10:55 pm
by Silver_Eclipse
yeah and then print those lines
Posted: Mon Aug 19, 2002 10:56 pm
by Silver_Eclipse
if (file_exists($filename)){
include 'style.css';
include 'header.php';
print $hmm2;
end ($file);
} else {
print "error";
}
is supposed to check if the file exists and thing print out those things if it does
Posted: Mon Aug 19, 2002 11:05 pm
by volka
ok, if there's no other need for storing the data (I think there is none, since you try to delete it afterwards

)why not directly print it to the browser?
Code: Select all
<?php
$if_name = "file.ext"; // inputfile_name
if (file_exists($if_name))
{
$f_contents = file($if_name);
$ln_gt = 62; // linenumber_greaterthan
$ln_lt = 4320; // linenumber_lesserthan
// include 'style.css'; <- uncertain about this
// include 'header.php'; <- uncertain and that
for ($ln = $ln_gt+1; $ln < count($f_contents) && $ln < $ln_lt; $ln++)
print($f_contentsї$ln]);
print("</table>");
}
else
printf('file not found: '.$if_name);
?>
the for-condition expresses
if ($array > $a and $array < $b)
but also assures that the loop while not iterate beyond the end of the file if it contained less lines than you expected.
'$ln = $ln_gt+1' | means starting at the next number after $ln_gt ($array > $a)
$ln < count($file) | keep within the bounds
&& $ln < $ln_lt | and '$array < $b'
$ln++ | after each iteration ('print($f_contents[$ln]);') increase the line number by 1
Posted: Mon Aug 19, 2002 11:07 pm
by Silver_Eclipse
i can print it directly to the browser but i want to store it because i plan on removing specific lines and adding my own later, so that is why i wish to store it.
Posted: Mon Aug 19, 2002 11:08 pm
by Silver_Eclipse
and because some of the data is statistics so im going to need that to do a day to day progress type thing. so i would need to store the data. but for now i just want it to store it and read it back.