Steven's Blog

A Dream Land of Peace!

Split Mids to Several Lines With Fixed Number Per Line

We have many mids with one mid every line, now we want to print all those mids out with a fixed number of mids per line. I want to realize this function in Perl first without success, so I am using PHP.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php

$scriptname = $argv[0];
$txt_file = $argv[1];
$dir = ".";

$contents = file_get_contents("$dir/$txt_file", FILE_USE_INCLUDE_PATH);
$contents = trim($contents);

$mid_splited = preg_split("/\n/", $contents);

$count_mids = count($mid_splited);

for ($i = 0; $i < $count_mids; $i++){
  print "$mid_splited[$i] ";
  if ($i % 7 == 0){
    print "\n";
  }
}


?>