如何在php中包含文件范围的行? [英] How do I include a range of lines of a file in php?
本文介绍了如何在php中包含文件范围的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道这:
<?php
$file2 = file('website/files/myfolder/file.html');
echo $file2[8];
echo $file2[9];
echo $file2[10];
echo $file2[11];
?>
将为我提供file.html文件中第8、9、10、11行的内容,但是我希望在第23至116行之间执行约100行.echo $ file2 [NUMBER];一百倍?
would give me the contents on lines 8,9,10,11 in the file.html file, however I would like to do this for about 100 lines ranging from lines 23 to 116. How would I accomplish this without using the echo $file2[NUMBER]; one hundrend times?
解释我要做什么的另一种方式可能是,如果我可以在php中做到这一点:
Another way to explain what I am trying to do would be possibly if I could do this in php:
echo $ file2 [23-116];
显然这是行不通的,但这就是概念.
obviously this will not work but that is the concept.
感谢您的帮助!
推荐答案
使用类似这样的循环
$data = file('website/files/myfolder/file.html');
for ($i = 23; $i <= 116; $i++) {
echo $data[$i];
}
$data = file('website/files/myfolder/file.html');
echo implode(PHP_EOL, array_splice($data, 23, 116 - 23));
- http://php.net/manual/en/function.array-splice.php
- http://php.net/manual/en/function.implode.php
这篇关于如何在php中包含文件范围的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文