在PHP中获取文本文件的前3行 [英] get the first 3 lines of a text file in php
本文介绍了在PHP中获取文本文件的前3行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用PHP开发网站,并且必须在索引中包括PHP文本文件的前三行.我该怎么办?
I am developing a website in PHP, and I must include in the index the first 3 lines of a text file in PHP. How can I do that?
<?php
$file = file_get_contents("text.txt");
//echo the first 3 lines, but it's wrong
echo $file;
?>
推荐答案
更加简单:
<?php
$file_data = array_slice(file('file.txt'), 0, 3);
print_r($file_data);
这篇关于在PHP中获取文本文件的前3行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文