读取txt文件的每一行到新的数组元素 [英] Read each line of txt file to new array element
本文介绍了读取txt文件的每一行到新的数组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将文本文件的每一行读入一个数组,并将每一行放入一个新元素中.
到目前为止我的代码.
I am trying to read every line of a text file into an array and have each line in a new element.
My code so far.
<?php
$file = fopen("members.txt", "r");
while (!feof($file)) {
$line_of_text = fgets($file);
$members = explode('\n', $line_of_text);
fclose($file);
?>
推荐答案
如果不需要任何特殊处理,这个 应该做你正在寻找的
If you don't need any special processing, this should do what you're looking for
$lines = file($filename, FILE_IGNORE_NEW_LINES);
这篇关于读取txt文件的每一行到新的数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文