This question already has an answer here:
I am saving my data in text file line by line through PHP code and which is done successfully.
But when I am retrieving the data from text file I am getting the whole content which I have entered in a file which means whenever I enter a new line in the text file and reads that file I get whole content of the file. So my query is that how it is possible to read only new line when I read the text file.
This what I have tried
$file = $_POST['read_fileid'];
$myFile = $file.".txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
</div>
fgets()
function can be used to read the file line by line:
$handle = fopen("input.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false)
{
//code to read file`
}
}
else
{
// error : file cannot be opened
}
fclose($handle);