Jump to content

[SOLVED] Loading txt file into an array


sdhunter

Recommended Posts

Hi guys, im new here and could do with some help.

I have a text file with items in it that i need to load into an array items.txt

pens

pencils

paints

 

Im loading up my txt file with this code, but its putting all 3 lines from the text file in the first slot on the array as [pens pencils paints].  I would like it to put them into 3 seperate slots [pens],[pencils],[paints].  Hope you can help.  thanks!

$myFile = "items.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));

fclose($fh);
$items = array($theData);
echo $items[0];

Link to comment
https://forums.phpfreaks.com/topic/149440-solved-loading-txt-file-into-an-array/
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.