= (strlen($tmp) - 1)) break; } } return $ret; } // wrap_lines($a, $width) /////////////////// // MAIN FUNCTION // /////////////////// /* Initialise */ if ($use_col_separator) $col_width - strlen($col_separator); if ($use_row_separator) $rows - substr_count($row_separator, $in_line_separator); $text_width = $col_width - $col_padding_width; $fin = fopen($in_file, "rb"); $fout = fopen($out_file, "w"); $out = array(); $row = 0; $col = 0; while (!feof($fin)) { // Here should be used explode(), but that function creates // greater array (by one item). Now we've got a problem if the // line is longer than 4096 chars //$in = explode($in_line_separator, $in); $in = fgets($fin, 4096); if ($replace_tab) $in = str_replace(chr(9), $tabs_to_space, $in); if ($replace_non_chars) $in = ereg_replace("[^ -\t$in_line_separator]", $non_chars_to, $in); $in = array($in); if ($auto_wrap) $in = wrap_lines($in, $text_width); for($i = 0; $i < sizeof($in); $i++) { if ($col == 0) { // first column $out[$row] = $in[$i]; } else { $out[$row] = rtrim( add_char($out[$row], $col_padding_char, $col * $col_width) . $in[$i]); } if ($use_col_separator) $out[$row] .= add_char("", $col_padding_char, ($col + 1) * $col_width - strlen($out[$row]) - strlen($col_separator) ) . $col_separator; $row++; $row = $row % $rows; if ($row == 0) { if ($use_row_separator) for ($j = 0; $j < sizeof($row_separator); $j++) $out[$rows + $j] .= add_char($row_separator[$j], $row_separator_padding_char, $col_width); $col++; $col = $col % $cols; if ($col == 0) { fwrite($fout, implode($out, $out_line_separator) . $out_line_separator); $out = array(); } } } } /* finally flush the accumulator, if anything was left in it and close all open files */ fclose($fin); fwrite($fout, implode($out, $out_line_separator) . $out_line_separator); fclose($fout); ?>