Zaloguj | Zarejestruj | FAQ
Anonymous

Reading from a text file

+ Odpowiedz

Posty: 2 Strona 1 z 1


Reading from a text file

przez SauravSutradhar » So sie 27, 2016 7:23 am

I am new to php programming. For reading a txt file , I created a txt file and in the same folder , I created the php file with the code:

<?php
$myfile= fopen("webdictionary.txt","r") or die("unable to open file");
echo fgets($myfile);
fclose($myfile);
?>

But I am unable to read the txt file. It is showing just a blank page.
Can you guys please help , i don't know what I am doing wrong.
Avatar użytkownika

SauravSutradhar

  • Posty: 1
  • Dołączył(a): So sie 27, 2016 7:06 am

Re: Reading from a text file

przez rhonda » N gru 25, 2016 6:05 pm

I am new to PHP but found this code on this website, html.net. It works for me. This not only reads the file but also reads line by line. Hope this helps.

<?php

// Opens the text file
$file= fopen("webdictionary.txt","r") or exit("unable to open file");

// Reads line by line until end of file
while(!feof($file)) {
echo fgets($file) . "<br />";
}
fclose($file);
?>
Avatar użytkownika

rhonda

  • Posty: 1
  • Dołączył(a): N gru 25, 2016 5:51 pm


+ Odpowiedz

Strona 1 z 1