Jump to content

php listing from text file


KickRocksBish

Recommended Posts

ok I have a text file that has ids listed each on a new line

 

how can I go about assigning each id to a variable

 

so like

 

12312412

23432443

34654366

56456345

 

the variable $ids = all of the ids above one at a time in an array

 

so like

 

$ids[] = 12312412;

$ids[] = 23432443;

$ids[] = 34654366;

$ids[] = 56456345;

 

 

Link to comment
https://forums.phpfreaks.com/topic/218716-php-listing-from-text-file/
Share on other sites

You could just use the file function to put each line of the file into an item within an array like:

 

$ids = file('your_text_file.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

 

The two FILE_*_LINES "flags" are used to trim new lines (which would ordinarily be appended to each item in the array) and to skip any empty lines, respectively.

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.