Read from file


Use fopen with the parameter r to open a file for reading and then use fgets to read the content line-by-line. Use fclose to close the filehandle. PHP closes the file at the end of the program but it is better practice to close it by ourself.


examples/files/readfile.php
<?php
    $fd = fopen("data/text.txt", "r");
    while ($line = fgets($fd)) {  
        print "$line<br>";
    }
    fclose($fd);
?>
<hr>
File should be displayed now