逐行讀取txt檔案並存入到陣列中 阿新 • • 發佈:2019-01-02 get_file_contents_on_line.php $file = fopen("log.txt", "r"); $user=array(); $i=0; //輸出文字中所有的行,直到檔案結束為止。 while(! feof($file)) { $user[$i]= fgets($file);//fgets()函式從檔案指標中讀取一行 $i++; } fclose($file); $user=array_filter($user); print_r($user);