preg_split():主题过长

时间:2019-02-26 23:22:17

标签: php function file preg-match

我正在尝试将文件内容解析为数组,实际上preg_match效果很好,但是对于大文件,它会引发以下错误:

//Roll dice again for the new point
diceRoll.Roll();
playGame.newPoint = diceRoll.randNum;

我正在尝试使用以下代码:

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

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

有什么主意吗?

1 个答案:

答案 0 :(得分:0)

您应该逐行阅读:

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

无论文件多大,您都将能够对其进行处理。