Jump to content

[SOLVED] file input line by line


Derleek

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/107676-solved-file-input-line-by-line/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.