I'm trying to parse a file content into an array, actually the preg_match works well but with a large file it throws me the follow error:
Warning: preg_split(): Subject is too long in /var/www/html/script.php on line 81
I'm trying with this code:
$fileLines = file($file);
foreach ($fileLines as $line) {
$rows = preg_split('/
/', $line);
$rowCount = 0;
// THEN I PROCESS THE ROWS
}
}
The actual file size is almost 2.5Gb, and I think is not a memory problem because I already increase the memory in the VPS and changed the configuration files.
Any idea?
You should read line by line:
$handle = fopen("inputfile.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
// process the line read.
}
fclose($handle);
} else {
// error opening the file.
}
No matter how big is your file, you are going to be able to process it.