I have a directory full of text files, I need to read every line, from every file into an array so I can display it using HTML. I'm grabbing the names of the files I need into an array using
if($dir = @opendir(calpath."includes/data/")) {
while (($eventsfile = readdir($dir)) !== false) {
if(preg_match('/^events\_[0-9]{4}\-[0-9]{2}\.conf$/', $eventsfile)) {
$filelist[] = $eventsfile;
}
}
closedir($dir);
}
Then I need to open each one and read each line into the next available index of an array. First I tried using
$events .= file('/home/echilon/public_html/db/'.$eventsfile);
But nothing happened. I thought I could try to read each file into a separate array, then merge them all. The main problem is that I don't know how many files there will be in the directory. I'm trying to use this ATM:
if(is_array($filelist)) {
$arys = 0;
foreach($filelist as $evfile) {
$eventsi.$$arys = file(calpath.'includes/data/'.$evfile);
$arys++;
}
for($i=0;$i<$arys;$i++) {
if($i == $arys-1) {
$mergestring .= '$eventsi'.$i;
} else {
$mergestring .= '$eventsi'.$i.', ';
}
}
// echo $mergestring;
$events = array_merge($mergestring);
foreach($events as $event) {
echo $event.'<br />';
}
}
If I echo $mergestring, the names of the arraya I need to merge are shown, but array_merge isn't accepting the string as a paramater, it's just printing the contents of $mergestring ($eventsi0, $eventsi1, $eventsi2, $eventsi3). What should be happening is $event in the last foreach loop should print every line of every text file.
Thanks for any help.