Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-06 20:02:39
Original
1631 people have browsed it

这篇文章主要介绍了php逐行读取txt文件写入数组的方法,涉及php文本文件及数组的相关操作技巧,需要的朋友可以参考下

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

假设有user.txt文件如下:

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

逐行读取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);

问题搞定!

希望本文所述对大家的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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!