squiblo Posted April 22, 2010 Share Posted April 22, 2010 file.txt line 1 line 2 line 3 test.php the following puts each line of the file into an array read('file.txt'); How can I show the content of file.txt without using the function readfile() and without showing it as an array. Thanks Link to comment https://forums.phpfreaks.com/topic/199408-reading-a-txt-file/ Share on other sites More sharing options...
MadTechie Posted April 22, 2010 Share Posted April 22, 2010 $myarray = read('file.txt'); //single echo $myarray[0]; //first item //loop foreach($myarray as $items){ echo "this is a item '$items'<BR />\n"; } Link to comment https://forums.phpfreaks.com/topic/199408-reading-a-txt-file/#findComment-1046553 Share on other sites More sharing options...
mattal999 Posted April 22, 2010 Share Posted April 22, 2010 Well you either look into fopen() or do this: <?php $fileArray = read("/path/to/file.txt"); foreach($fileArray as $line) { echo $line."<br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/199408-reading-a-txt-file/#findComment-1046555 Share on other sites More sharing options...
litebearer Posted April 22, 2010 Share Posted April 22, 2010 Perhaps... $string = file_get_contents('file.txt'); echo $string; Link to comment https://forums.phpfreaks.com/topic/199408-reading-a-txt-file/#findComment-1046561 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.