Read txt file and repeat lines based on data in file - Write to array or another file.
Posted: Fri Sep 03, 2021 9:38 am
First of all, thank you for your help on this.
I have only worked with PHP occasionally and not very very good at it, so I might just be missing a concept or logic.
If you could point me in the right direction, so I can research functionality further that would be great.
I am trying to write a php script that has two requirements:
1) Read a txt file line by line, and write it to an array or another text file.
To meet this requirement I am currently using file() and a foreach to read file line by line to meet the first requirement.
2) Column one of each line will contain an integer. Based on that integer(x), I want to repeat the line x times in the array or file and then move onto next line.
Is this something that I can accomplish with a php script?
2 line sample file. First line should be repeated 6 times and Line 2 repeated 104.
Script should be able to process hundreds of lines.
6 ItemNum1 12846503015697 432 72
104 ItemNum2 34844923450575 7488 72
I have only worked with PHP occasionally and not very very good at it, so I might just be missing a concept or logic.
If you could point me in the right direction, so I can research functionality further that would be great.
I am trying to write a php script that has two requirements:
1) Read a txt file line by line, and write it to an array or another text file.
To meet this requirement I am currently using file() and a foreach to read file line by line to meet the first requirement.
2) Column one of each line will contain an integer. Based on that integer(x), I want to repeat the line x times in the array or file and then move onto next line.
Is this something that I can accomplish with a php script?
2 line sample file. First line should be repeated 6 times and Line 2 repeated 104.
Script should be able to process hundreds of lines.
6 ItemNum1 12846503015697 432 72
104 ItemNum2 34844923450575 7488 72