Last updated on November 18th, 2015 at 03:47 am
Simple php code for reading lines
Using the below script you can easily read a txt file. Let the text file be mistonline.in.txt and you are using fopen() to open the file and ‘r’ argument to Read the file which is opened.
<?php $file = fopen("mistonline.in.txt", "r") or exit("Unable to open file!"); //Output of the text file while(!feof($file)) { //<br> is used to break b/w lines echo fgets($file). "<br />"; } fclose($file); ?>
fclose() as the name says will close the file once the read operation is done. It is always a best practice to close the file once data is read.
nice
wow, but how about if i want to read the file and add some record without any loss of data,..? thanks in advance
Jeremy thanks again for your response
Follow this link, it will be helpful and will clear your doubt i guess.
i didn’t understand the functions used in the script. What does fgets functions do ? is it fetch data from the file ?
Please refer, http://php.net/manual/en/function.fgets.php for more info regarding fgets. 🙂