Derleek Posted May 28, 2008 Share Posted May 28, 2008 So, i'm wondering how to go about reading info from a file and storing it into an array line by line. I'm making a game and want to be able to change the options of it by reading it into a file so the file would look like this... 'option1 option2 option3 option4... etc' and i need to place them into a drop down menu. Here is what i have tried... but i keep gettin really reeeeaaally funk results... $content = file('myfile.txt'); $numLines = count($content); for ($i = 0; $i < $numLines; $i++) { $line = trim($content[$i]); echo $line[$i]; } but when i input the file that contains the text: 'option1 option2 option3 option4 etc' I only get out 'opti' for the echo... i'm probably not understanding how the file is stored in the array correctly... i duno Quote Link to comment https://forums.phpfreaks.com/topic/107676-solved-file-input-line-by-line/ Share on other sites More sharing options...
sasa Posted May 28, 2008 Share Posted May 28, 2008 change line echo $line[$i]; to echo $line; Quote Link to comment https://forums.phpfreaks.com/topic/107676-solved-file-input-line-by-line/#findComment-551995 Share on other sites More sharing options...
craygo Posted May 28, 2008 Share Posted May 28, 2008 can also do this <?php $content = file('myfile.txt'); foreach($content as $l) { $line = trim($l); echo $line."<br>"; } ?> Ray Quote Link to comment https://forums.phpfreaks.com/topic/107676-solved-file-input-line-by-line/#findComment-551999 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.