Posted By:
16 Mar, 2014 3:27 am PDT

Reading file in PHP

How to read the file using PHP?


Here in PHP we have fgets() function which can be to read line in a file and feof()  is used to check whether the end of file is reached or not.It will become more clear from the following example.

//Reading file in PHP


<!DOCTYPE html>




$file = fopen("text.txt","r");

while( !feof($file))


echo fgets($file)."<br/>";







/*Output of above program is:

This is PHP Programming.



This shows how to open a file and how to read a line from that file using PHP.

This file can be any text file.(with .txt extension).

Attachment: read.php
Was it useful?  

Please login to reply to this problem.