fork download
  1. <?php
  2. $input = 'line1
  3. line2
  4. line3
  5. line4
  6. line5
  7. line6
  8. line7
  9. line8
  10. line9
  11. line10
  12. line11
  13. line12';
  14. $txtcontent = explode("\n", $input);
  15. $input = array_chunk($txtcontent, 9, false);
  16. foreach($input as $key => $array){
  17. foreach($array as $k => $v){
  18. $input[$key][$k] = '\text '.($k*6+1).',1,'.$v;
  19. }
  20. }
  21. function array_flatten($array) {
  22. if (!is_array($array)) {
  23. return FALSE;
  24. }
  25. $result = array();
  26. foreach ($array as $key => $value) {
  27. if (is_array($value)) {
  28. $result = array_merge($result, array_flatten($value));
  29. }
  30. else {
  31. $result[$key] = $value;
  32. }
  33. }
  34. return $result;
  35. }
  36. $array = array_flatten($input);
  37. print_r($array);
  38. ?>
Success #stdin #stdout 0.03s 13064KB
stdin
Standard input is empty
stdout
Array
(
    [0] => \text 1,1,line1
    [1] => \text 7,1,line2
    [2] => \text 13,1,line3
    [3] => \text 19,1,line4
    [4] => \text 25,1,line5
    [5] => \text 31,1,line6
    [6] => \text 37,1,line7
    [7] => \text 43,1,line8
    [8] => \text 49,1,line9
    [9] => \text 1,1,line10
    [10] => \text 7,1,line11
    [11] => \text 13,1,line12
)