Hi
I've got this function, listed below. It's designed to read e-mailaddresses from a file and display line x to line y from that file
(ie: start at line 100 and end at line 300).
It works perfectly but my problem is that it reads the entire file into an array before selecting the lines to be displayed.
I was wondering if it's possible to read just the lines that have to be displayed from this file instead of placing the whole file into an array.
I will be working with large files so reading all of them will slow down my code too much.
$this->file = filename to read from
$this->start = start reading file from this line
$this->end = read to this line in file
function read_addr(){
// reads addresses into memory
$text_array = file ($this->file); //read file into array
array_unique($text_array); // remove doubles from array
$start = $this->start; //starting position in array
$end = $this->end; //ending position in array
//set pointer to active starting line
while(current($text_array)){
if(key($text_array) == $start){
break;
}
next($text_array);
}
// iterates through the lines
while ((list ($sleutel, $waarde) = each ($text_array)) && ($sleutel<=$end)){
echo "#$sleutel : $waarde <br>";
}
}
}