Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP只读文件的一部分_Php - Fatal编程技术网

PHP只读文件的一部分

PHP只读文件的一部分,php,Php,我用这种方式读/写文件的所有内容 $file = 'c:\file.txt'; $new = 'c:\new.txt'; $current = file_get_contents($file); file_put_contents($new, $current); FILE.TXT some text some text etc.. -----START----- some text some text etc.. -----STOP------ some text some text et

我用这种方式读/写文件的所有内容

$file = 'c:\file.txt';
$new = 'c:\new.txt';

$current = file_get_contents($file);
file_put_contents($new, $current);
FILE.TXT

some text
some text
etc..
-----START-----
some text
some text
etc..
-----STOP------
some text
some text
etc..
现在我只想获取文件内容的一部分,并将输出写入另一个文件。 我的目标是只写这篇文章

-----START-----
some text
some text
etc..
-----STOP------
或者从第------行开始------(包括在内)到文件结束

我怎么能这样做?谢谢

您可以使用:

“几乎”是完美的,但我不写行“-----停---”
$open = '-----START-----';
$close = '-----STOP-----';
$current = file_get_contents($file);
$result = strstr(strstr($current, $open), $close, true). $close;
file_put_contents($conf_file, $result);