I have a txt file that is almost 2 Mb. It has lines with a time, date, name and a message. I would like to do a regular expression on each line, so I start by reading the file into an array.
$array1 = file('<file_name>');
Between each line in the file is a whiteline that I would like to skip. On stackoverflow I found the following peace of code which seems to be ok.
array_values( array_filter($array1, 'trim'));
My problem is that this takes very long to process.
$array2 = array_values( array_filter($array1));
or
$array2 = array_values( array_filter($array1));
unset($array1);
If you want to optimize memory, you'll have to read each line and process it.
Use fopen, fread, fclose php functions. You'll find some information here