Jump to content

Detect line from text file


mekdonel

Recommended Posts

Hi,

 

I have a text file that list out several activation code

aaaaa1
aaaaa2
aaaaa3
aaaaa4
aaaaa5

 

Then I will create a form which user will enter the line number of the text file to get the activation code. Eg user enter '2', so the system will pop out 'aaaaa2'.

 

The Problem is I really stuck on how to get php call the line number in the text file.

 

Any help will be grateful. Thanks

Link to comment
https://forums.phpfreaks.com/topic/59937-detect-line-from-text-file/
Share on other sites

Open the file using the file function like so:

$line = file('path/to/file');

 

file opens up the file and puts each line in to an array, eg: $line[0] is line 1, $line[1] is line 2, $line[2] is line 3. Remember array indices start at 0 and not 1.

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.