1 ,'perColumn' => 10 )); Markup('createColumns', 'arguments for table, 2=>text (all items) global $CreateColumnsDefaults; # echo " *** text = " . $mat[2] . " *** match = " . $mat[1] . " *** "; # gather up args $args = ParseArgs($mat[1]); # add default parameters before parsing arguments $args = array_merge($CreateColumnsDefaults, $args); # uses CreateColumnsDefaults, unless supplied by user # tablestart and -end markup can be suppressed by setting tableMarkup=0 $tableMarkup_enabled = $args['tableMarkup']; if ($tableMarkup_enabled) { # table setup $tableOptions = $args['tableOptions']; if($tableOptions) $tableStart = "(:table $tableOptions:)"; else $tableStart = "(:table:)"; $tableEnd = "(:tableend:)"; } # new column markup should execute no matter what $cellOptions = $args['cellOptions']; if($cellOptions) { $newColumn = "(:cell $cellOptions:)"; $newColumnNewRow = "(:cellnr $cellOptions:)"; } else { $newColumn = "(:cell:)"; $newColumnNewRow = "(:cellnr:)"; } # number of columns -- if this is present, then it will override any perColumn argument $numCol = $args['nColumns']; # number of columns # break up text, line-by-line $textArray = explode("\n", $mat[2]); # remove empty slots $textArrayClean = []; foreach($textArray as $item) { if ($item) $textArrayClean[] = $item; } $count = count($textArrayClean); #echo " *** numCol=$numCol cleanCount = $count *** "; # if $numCol is present, determine $perCol if ($numCol) { $perCol = ceil($count / $numCol); # number of items per column } else { # if $numCol not present, then use $perCol to determine number of Columns $perCol = $args['perColumn']; # number of items per column } # insert new column/cell markup $i = 0; $textWithColumns = ''; foreach($textArrayClean as $txt) { # insert new column markup every Nth item if( ($i % $perCol)===0 ) { # 1st one should be (:cellnr:) (in case there is any preceding table markup) if ($i===0) { $textWithColumns .= "$newColumnNewRow\n"; } else { # all remaining columns should be (:cell:) $textWithColumns .= "$newColumn\n"; } } # add text entries line per line $textWithColumns .= $txt."\n"; $i++; } # don't add tablestart and tableend markup if tableMarkup=0 if($tableMarkup_enabled) $textWithColumns = "$tableStart\n$textWithColumns\n$tableEnd"; # echo " *** textWithColumns = $textWithColumns ***"; return $textWithColumns; }