Read File
2003-02-17 00:20:09
Category: php:files
Description: Read in text from a file.
Author: detour
Viewed: 4148
Rating: (24 votes)


<?php
  // readfile.php by detour@metalshell.com
  //
  // Read in text from a file.
  //
  // http://www.metalshell.com/
  //
 
  $yourfile = '/tmp/file';
 
  // Open the file for reading.
  $fd = fopen($yourfile, "r");
  
  // Read in all of the data in one big hunk
  $data = fread($fd, filesize($yourfile));
 
  // Close the file.
  fclose($fd);
 
  // Convert all return char's to <br> for html
  $data = ereg_replace("\n", "<br>", $data);
 
  // Print it all out.
  echo $data;
 
?>