tarleton Posted August 19, 2010 Share Posted August 19, 2010 Hi, Have a text file that is being read. I want to print the contents however I want each line of the text file to appear on a new line in the browser. So far $str = file_get_contents('records.txt'); $lines = explode("\n", $str); echo $lines[0]; Help appreciated Link to comment https://forums.phpfreaks.com/topic/211146-loop-echo-text-file-line/ Share on other sites More sharing options...
abdfahim Posted August 19, 2010 Share Posted August 19, 2010 $file=fopen("records.txt","r"); while(!feof($file)){ $a=fgets($file,4096) ; echo $a."<BR>"; } fclose($file); Link to comment https://forums.phpfreaks.com/topic/211146-loop-echo-text-file-line/#findComment-1101119 Share on other sites More sharing options...
wildteen88 Posted August 19, 2010 Share Posted August 19, 2010 It is a lot easier to use file $lines = file('somefile.txt'); foreach($lines as $line) { echo "$line<br />"; } Link to comment https://forums.phpfreaks.com/topic/211146-loop-echo-text-file-line/#findComment-1101317 Share on other sites More sharing options...
AbraCadaver Posted August 19, 2010 Share Posted August 19, 2010 echo nl2br(file_get_contents('records.txt')); Link to comment https://forums.phpfreaks.com/topic/211146-loop-echo-text-file-line/#findComment-1101334 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.