Tips & Tricks

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 [code]fopen()[/code] and [code]fgets()[/code] function.

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

Let’s for the code:

[cc lang=”php”]
$file = “/path/to/the/file”;
$fp = fopen($file, “r”);
while ( $line = fgets($fp, 1000) )
{
echo $line;
}
[/cc]

Shares:

Leave a Reply

Your email address will not be published. Required fields are marked *