Jump to content

Hard PHP Question, regarding files


Rifts

Recommended Posts

Please delete my other post as I realized it is not what I needed and I cannot delete it myself.

 

Here is exactly what I need.

 

I have X amount of text files (with random names) in each text file there is Y amount of lines with one word on each line.

 

I need to open all X amount of files and take the first line from each and save it in a new txt doc. then take the second line of each and save them to a new text doc. and so on.

 

so I have all the line 1's from all the txt files together

and all the line 2's together etc.

 

 

I hope that makes sense.

 

 

 

 

Link to comment
Share on other sites

This should be pretty simple to do. I'm not sure of the file structure though so I can only suggest how to obtain the files; scandir will allow you scan through all files in a directory, and glob would allow you to match specific files (i.e. all "*.txt" files) and loop through them.

 

Once you're looping through your file list, open each file with the file function which will return the contents as an array (split by line). You can then loop through each line, storing the value (plus "\n" for a new line) to the correct text file.

Link to comment
Share on other sites

ahhh thank you both for the answers they sound like they are exactly what I need. I'm no pro at php so I could use a little more help.

 

the file structures will all be the same and its really simple. they will all have the exact same amount of lines. and each line will have a 12 letter word on them also there will never be a duplicate.

 

 

Thanks a lot I appreciate it

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.