irwan

PHP : read file to array

Mar 15th, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.33 KB | None | 0 0
  1. <?php
  2. // file example 1: read a text file into an array, with
  3. // each line in a new element
  4.  
  5. $filename="input.txt";
  6. $lines = array();
  7. $file = fopen($filename, "r");
  8. while(!feof($file)) {
  9.  
  10.     //read file line by line into a new array element
  11.     $lines[] = fgets($file, 4096);
  12.  
  13. }
  14. fclose ($file);
  15. print_r($lines);
  16. ?>
Advertisement
Add Comment
Please, Sign In to add comment