preg_split():主题太长了

问题描述 投票:3回答:1

我正在尝试将文件内容解析为数组,实际上preg_match运行良好,但是对于大文件,它会抛出以下错误:

Warning: preg_split(): Subject is too long in /var/www/html/script.php on line 81

我正在尝试使用此代码:

$fileLines = file($file);
    foreach ($fileLines as $line) {
        $rows = preg_split('/\n/', $line);
        $rowCount = 0;
        // THEN I PROCESS THE ROWS
    }
}

实际文件大小几乎是2.5Gb,我认为不是内存问题,因为我已经增加了VPS中的内存并更改了配置文件。

任何的想法?

php function file preg-match
1个回答
0
投票

你应该逐行阅读:

$handle = fopen("inputfile.txt", "r");
if ($handle) {
    while (($line = fgets($handle)) !== false) {
        // process the line read.
    }
    fclose($handle);
} else {
    // error opening the file.
} 

无论您的文件有多大,您都可以处理它。

© www.soinside.com 2019 - 2024. All rights reserved.