How to read the text file using PHP

How to read the text file using PHP. Many times we need to store some data in the text file and read the text file. So, today we are learning how we can read the text file.

Let’s see it’s too easy to read the text file using PHP like below.

$file_handle = fopen("pathtofile.txt", "r");
$content = "";
while (!feof($file_handle)) {
    $content[] = fgets($file_handle);
}
fclose($file_handle);

echo '<pre>';
print_r($content);
exit;

Just set the text file path that you want to read.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s