Per criticism, I have focused the question to PHP, but alternative solutions--including javascript, python, and Excel--are acceptable.
Given the following list how do break it into a tab-delineated csv at every nth record (i.e., 3) ?
Apples
Sweet and juicy, these babies are in season!
$2
Bananas
Packed with essential vitamins, our organic bananas are perfect for a snack!
$1
Peaches
Juicy Georgia peaches are available!
$2
Tomatoes
Our variety is the perfect mix of juicy and hearty for your summer salads!
$1
Cucumbers
These cucumbers pair with tomatoes for amazing salads.
$2
The desired output would be
Apples\tSweet and juicy, these babies are in season!\t$2\n
Bananas\tPacked with essential vitamins, our organic bananas are perfect for a snack!\y$1\n
Peaches\tJuicy Georgia peaches are available!\t$2\n
Tomatoes\tOur variety is the perfect mix of juicy and hearty for your summer salads!\t$1\n
Cucumbers\tThese cucumbers pair with tomatoes for amazing salads.\t$2\n
I have attempted this exercise in SublimeText with regex but cannot master the pattern to match every nth occurrence.
Any solution will do. I just need to parse thousands of records into a spreadsheet.