PHP 读取 txt 文件

<?php
header('Content-Type: text/html; charset=utf-8');

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

效果图:

 

扫描二维码关注公众号,回复: 242364 查看本文章

猜你喜欢

转载自onestopweb.iteye.com/blog/2407691