submitted by: Guest

PHP: read file to a string

Read a text file to a string variable using fgets.


code snippet:
<?php
// file example 1: read a text file into a string with fgets

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

    
//read file line by line into variable
  
$output $output fgets($file4096);
 
}
fclose ($file);
echo 
$output;

?>

notes:
this bare-bones example does not provide any error checking whatsoever.