将一个每行一个item的多行文本转变成每行固定数目的item的文本(PHP) 2014 年7 月17 日 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"; } } ?>