Read Text File using PHP

Here is the simple trick to read the text file line by line. For this I am going to use the fopen() and fgets() function.

This is code snippet I am going to take one text file and read it line by line.

Let’s for the code:

$file = "/path/to/the/file"; $fp = fopen($file, "r"); while ( $line = fgets($fp, 1000) ) { echo $line; }
$file = "/path/to/the/file";
$fp = fopen($file, "r");
while ( $line = fgets($fp, 1000) )
  echo $line;

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by: