Home > php教程 > php手册 > php逐行读取txt文件写入数组的方法 原创,

php逐行读取txt文件写入数组的方法 原创,

WBOY
Release: 2016-06-13 08:58:50
Original
1244 people have browsed it

php逐行读取txt文件写入数组的方法 原创,

本文实例讲述了php逐行读取txt文件写入数组的方法。分享给大家供大家参考。具体如下:

假设有user.txt文件如下:

user01
user02
user03
user04
user05
user06
user07
user08
user09
user10
user11
user12

Copy after login

逐行读取user.txt并写入数组的方法如下:

$file = fopen("username.txt", "r");
$user=array();
$i=0;
//输出文本中所有的行,直到文件结束为止。
while(! feof($file))
{
 $user[$i]= fgets($file);//fgets()函数从文件指针中读取一行
 $i++;
}
fclose($file);
$user=array_filter($user);
print_r($user);

Copy after login

问题搞定!

希望本文所述对大家的php程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template