submitted by:

PHP: read file to array

This simple PHP example shows how to read a text file into an array, with each line of the file as a seperate element.


code snippet:
<?php
// file example 1: read a text file into an array, with
// each line in a new element

$filename="input.txt";
$lines = array();
$file fopen($filename"r");
while(!
feof($file)) {

    
//read file line by line into a new array element
    
$lines[] = fgets($file4096);
  
}
fclose ($file);
print_r($lines);
?>