用php读取纯文本文件 [英] Read a plain text file with php
本文介绍了用php读取纯文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的服务器中有一个包含此信息的文本文件:
I have a text file with this information in my server:
Data1
Data2
Data3
.
.
.
DataN
如何使用PHP(逐行)读取文本文件中的所有信息?
How do I read all the information from the text file (line by line) using PHP?
推荐答案
<?php
$fh = fopen('filename.txt','r');
while ($line = fgets($fh)) {
// <... Do your work with the line ...>
// echo($line);
}
fclose($fh);
?>
这将使您逐行阅读..阅读有关行尾的 php.net/fgets 上的注释Mac问题.
This will give you a line by line read.. read the notes at php.net/fgets regarding the end of line issues with Macs.
这篇关于用php读取纯文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文