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 Quote 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"; } Quote 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 />"; } ?> Quote 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; Quote Link to comment https://forums.phpfreaks.com/topic/199408-reading-a-txt-file/#findComment-1046561 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.