Letters
Moderator: General Moderators
-
Silver_Eclipse
- Forum Commoner
- Posts: 61
- Joined: Sun Aug 18, 2002 7:26 pm
-
Silver_Eclipse
- Forum Commoner
- Posts: 61
- Joined: Sun Aug 18, 2002 7:26 pm
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";
}
?>wow, gets harder to concentrate from minute to minute
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?
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 thiswhile(list($array) = each($file))
{
if ($array > $a and $array < $b)
fputs ($fe, $file[$array], 100000);
}
Code: Select all
for ($a=$a+1; $a<count($file) && $a<$b; $a++)
fputs ($fe, $fileї$a], 100000);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.if (file_exists($filename))
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?
Last edited by volka on Mon Aug 19, 2002 10:39 pm, edited 1 time in total.
-
Silver_Eclipse
- Forum Commoner
- Posts: 61
- Joined: Sun Aug 18, 2002 7:26 pm
-
Silver_Eclipse
- Forum Commoner
- Posts: 61
- Joined: Sun Aug 18, 2002 7:26 pm
-
Silver_Eclipse
- Forum Commoner
- Posts: 61
- Joined: Sun Aug 18, 2002 7:26 pm
-
Silver_Eclipse
- Forum Commoner
- Posts: 61
- Joined: Sun Aug 18, 2002 7:26 pm
-
Silver_Eclipse
- Forum Commoner
- Posts: 61
- Joined: Sun Aug 18, 2002 7:26 pm
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?
the for-condition expresses
'$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
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);
?>but also assures that the loop while not iterate beyond the end of the file if it contained less lines than you expected.if ($array > $a and $array < $b)
'$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
Last edited by volka on Mon Aug 19, 2002 11:07 pm, edited 1 time in total.
-
Silver_Eclipse
- Forum Commoner
- Posts: 61
- Joined: Sun Aug 18, 2002 7:26 pm
-
Silver_Eclipse
- Forum Commoner
- Posts: 61
- Joined: Sun Aug 18, 2002 7:26 pm