Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.