Jump to content

[SOLVED] Text Processing. Making folders based on data- whaaattt??!?


physaux

Recommended Posts

Hey guys, I got a big project ahead of me, I was hoping someone could point me in the right direction.

 

So I have a text file, that I downloaded. It is formatted like so:

ID [TAB] NAME [TAB] RANK1 [TAB] RANK2...

ID [TAB] NAME [TAB] RANK1 [TAB] RANK2...

ID [TAB] NAME [TAB] RANK1 [TAB] RANK2...

ID [TAB] NAME [TAB] RANK1 [TAB] RANK2...

ID [TAB] NAME [TAB] RANK1 [TAB] RANK2...

...//and so on

 

What I want to do is essentially "batch process" this text file, to create the following folder structure:

The main folder would have different folders inside of it, one for each "RANK1".

In of these folders, there would be another folder for "RANK2"

 

ex:

ID [TAB] NAME [TAB] dog [TAB] charlie...

ID [TAB] NAME [TAB] dog [TAB] woof...

ID [TAB] NAME [TAB] cat [TAB] meow...

 

would create:

[dog], [cat]

inside of [dog], there would be two folders; [charlie],[woof]

inside of [cat], there would be one folder; [meow]

 

Get it?

 

Ok, Now the last part. Inside of each final folder, I want to place a text file with some text. Ex:

in [dog][charlie] I would place index.php, contents = "THIS IS CHARLIE THE DOG"

 

MY IDEAS:

I would read the text file line by line, then "explode" each line by the "tab" into an array, which I would then analyze. How would i go from there? Thanks!

 

 

 

 

Could anyone point me in the right direction? Ty

Once you have a row loaded, you can simply use file_exists to check if $arr[2] exists, if it doesn't then create it using mkdir, then check if $arr[2] . "/" . $arr[3] exists and do the same, stop rinse repeat for each level you have.

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.