Read a text file in PHP

by MD on 2009/09/25

Using this script, a text file can be read and can be displayed on a php page

<?php
    $filename = "dak.txt";
    	// set file to read

    $fh = fopen ($filename, "r") or die("Could not open file");
	// open file
    while (!feof($fh)) {
	// read file
        $data = fgets($fh);
        echo "<br>".$data;
    }
	// close file
    fclose ($fh);

    echo "<p>Contents of file ".$filename." are are shown above ";
?>

You may also like:

Leave a Comment

Previous post:

Next post: