The easiest way to read from a text file is to grab a whole line through fgets (think of the final s as standing for “string”)
<?php $fh = fopen("testfile.txt", 'r') or die("File does not exist or you lack permission to open it"); $line = fgets($fh); fclose($fh); echo $line; ?>
If you created the file textfile.txt, you’ll get the first line:
Line 1
Or you can retrieve whole file as in following example
<?php $fh = fopen("testfile.txt", 'r') or die("File does not exist or you lack permission to open it"); $theData = fread($fh, filesize("testfile.txt")); echo $theData; fclose($fh); ?>