从特定行读取文件,直到 laravel 中的另一特定行

Read file from specific line until another specific line in laravel

我有这样的文件

#####
....
....
.....
###one
... 
...
...
###two
.... 
....
##### 

我想从 ###one 读到 ###two
我不想逐行阅读

刚测试过,效果很好:

preg_match('/###one(.*?)###two/s', $fileContents, $output);

echo $output[1];

另一种方式供考虑但也需要读取整个文件:

<?php
$s = file_get_contents('the_file'); 
$ans = explode('###two', explode('###one', $s, 2)[1], 2)[0]; 
echo $ans;