Reading a File into an Array : file function « File Directory « PHP






Reading a File into an Array

 
file() function reads the entire contents of a file into an indexed array. 

Its syntax is: array file (string file [, int use_include_path])

If use_include_path is set to 1, then the file is searched along the include path in the php.ini file. 

<?
$file_array = file( 'data.txt' );

while ( list( $line_num, $line ) = each( $file_array ) ) :
     print "<b>Line $line_num:</b> " . htmlspecialchars( $line ) . "<br>\n";
endwhile;
?>
  
  








Related examples in the same category

1.file.php
2.PHP File Logic Functions