Nieuw lid |
|
Hoe krijg ik deze array weggeschreven naar een bestand?
Zoals ik dat nu toepas krijg ik alleen de laatste regel van de array, maar ik wil de volledige array wegschrijven.
<?
$fp = fopen ("http://www.zuid-west.nevobo.nl/standvol.htm","r"); //just for testing
define("SKIPFIRST", 2495); //skip fist y lines
define("SKIPLAST", 24623); //skip last x lines
$linecount = 0;
$buffer = array();
for($i=0; $i<SKIPLAST; $buffer[$i++]=false); // (*)
$bp = 0; //buffer pointer (points to oldest element in the buffer)
while (!feof($fp)) {
$line = fgets($fp, 4096); // read next line
if(!$line) continue; //skip empty lines (**)
if ($linecount++ < SKIPFIRST) continue; // skip fist y lines
$oldline = $buffer[$bp]; // retreive old line
$buffer[$bp] = $line; // put in new line
$bp = ($bp+1)%SKIPLAST; // set pointer to the oldes line in the buffer
if($oldline){ //NOTE: the first SKIPLAST times $oldline will be false (see *), but also when an empty line is found (this will however not be the case because of (**))
// do something with the line
echo $oldline;
$file ="file";
$handle = fopen($file, "w");
fwrite($handle, $oldline);
fclose ($handle);
}
}
?>
<? $fp = fopen ("http://www.zuid-west.nevobo.nl/standvol.htm","r"); //just for testing define("SKIPFIRST", 2495); //skip fist y lines define("SKIPLAST", 24623); //skip last x lines $linecount = 0; for($i=0; $i<SKIPLAST; $buffer[$i++]=false); // (*) $bp = 0; //buffer pointer (points to oldest element in the buffer) $line = fgets($fp, 4096); // read next line if(!$line) continue; //skip empty lines (**) if ($linecount++ < SKIPFIRST) continue; // skip fist y lines $oldline = $buffer[$bp]; // retreive old line $buffer[$bp] = $line; // put in new line $bp = ($bp+1)%SKIPLAST; // set pointer to the oldes line in the buffer if($oldline){ //NOTE: the first SKIPLAST times $oldline will be false (see *), but also when an empty line is found (this will however not be the case because of (**)) // do something with the line $file ="file"; $handle = fopen($file, "w"); } } ?>
(bron : http://www.html-site.nl/forum/11_882_0.html)
Bijvoorbaat dank!
|