13 March 2010, 06:11:29
Open a blank text file in any text editor such as Windows Notepad or GEdit and Kate in Linux.
Begin typing the PHP script in the blank text file:
<?php
Open the file with the fopen function:
$file = fopen("example.txt", 'r');
The 'r' parameter tells the fopen function to open the file for reading only.
Begin the while statement that will loop until the end of the file:
while (!feof($file)) {
Read the file with the fgets function and place it in the variable $data:
$data = fgets($file);
The fgets function will read the file line-by-line unless a byte limit is provided.
Print each line to the screen and close the while loop:
echo $data;}
Close the file:
fclose($file);
End the PHP script:
?>
The entire script will look like:
<?php
$file = fopen("example.txt", 'r');
while (!feof($file)) {
$data = fgets($file);
echo $data;}
fclose($file);
?>
Begin typing the PHP script in the blank text file:
<?php
Open the file with the fopen function:
$file = fopen("example.txt", 'r');
The 'r' parameter tells the fopen function to open the file for reading only.
Begin the while statement that will loop until the end of the file:
while (!feof($file)) {
Read the file with the fgets function and place it in the variable $data:
$data = fgets($file);
The fgets function will read the file line-by-line unless a byte limit is provided.
Print each line to the screen and close the while loop:
echo $data;}
Close the file:
fclose($file);
End the PHP script:
?>
The entire script will look like:
<?php
$file = fopen("example.txt", 'r');
while (!feof($file)) {
$data = fgets($file);
echo $data;}
fclose($file);
?>