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

Link to comment
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.