public function format($columns, $texts, $colors = array())
    {
        $columns = $this->calculateColLengths($columns);

        $wrapped = array();
        $maxlen = 0;

        foreach ($columns as $col => $width) {
            $wrapped[$col] = explode("\n", $this->wordwrap($texts[$col], $width, "\n", true));
            $len = count($wrapped[$col]);
            if ($len > $maxlen) {
                $maxlen = $len;
            }

        }

        $last = count($columns) - 1;
        $out = '';
        for ($i = 0; $i < $maxlen; $i++) {
            foreach ($columns as $col => $width) {
                if (isset($wrapped[$col][$i])) {
                    $val = $wrapped[$col][$i];
                } else {
                    $val = '';
                }
                $chunk = $this->pad($val, $width);
                if (isset($colors[$col]) && $colors[$col]) {
                    $chunk = $this->colors->wrap($chunk, $colors[$col]);
                }
                $out .= $chunk;

                // border
                if ($col != $last) {
                    $out .= $this->border;
                }
            }
            $out .= "\n";
        }
        return $out;

    }
public function format($columns, $texts, $colors = array())
    {
        $columns = $this->calculateColLengths($columns);

        $wrapped = array();
        $maxlen = 0;

        foreach ($columns as $col => $width) {
            $wrapped[$col] = explode("\n", $this->wordwrap($texts[$col], $width, "\n", true));
            $len = count($wrapped[$col]);
            if ($len > $maxlen) {
                $maxlen = $len;
            }

        }

        $last = count($columns) - 1;
        $out = '';
        for ($i = 0; $i < $maxlen; $i++) {
            foreach ($columns as $col => $width) {
                if (isset($wrapped[$col][$i])) {
                    $val = $wrapped[$col][$i];
                } else {
                    $val = '';
                }
                $chunk = $this->pad($val, $width);
                if (isset($colors[$col]) && $colors[$col]) {
                    $chunk = $this->colors->wrap($chunk, $colors[$col]);
                }
                $out .= $chunk;

                // border
                if ($col != $last) {
                    $out .= $this->border;
                }
            }
            $out .= "\n";
        }
        return $out;

    }
public function format ( $ columns , $ texts , $ colors = array ( ) ) { $ columns = $ this -> calculateColLengths ( $ columns ) ; $ wrapped = array ( ) ; $ maxlen = 0 ; foreach ( $ columns as $ col => $ width ) { $ wrapped [ $ col ] = explode ( "\n" , $ this -> wordwrap ( $ texts [ $ col ] , $ width , "\n" , true ) ) ; $ len = count ( $ wrapped [ $ col ] ) ; if ( $ len > $ maxlen ) { $ maxlen = $ len ; } } $ last = count ( $ columns ) - 1 ; $ out = '' ; for ( $ i = 0 ; $ i < $ maxlen ; $ i ++ ) { foreach ( $ columns as $ col => $ width ) { if ( isset ( $ wrapped [ $ col ] [ $ i ] ) ) { $ val = $ wrapped [ $ col ] [ $ i ] ; } else { $ val = '' ; } $ chunk = $ this -> pad ( $ val , $ width ) ; if ( isset ( $ colors [ $ col ] ) && $ colors [ $ col ] ) { $ chunk = $ this -> colors -> wrap ( $ chunk , $ colors [ $ col ] ) ; } $ out .= $ chunk ; // border if ( $ col != $ last ) { $ out .= $ this -> border ; } } $ out .= "\n" ; } return $ out ; }
Displays text in multiple word wrapped columns

@param int[] $columns list of column widths (in characters, percent or '*')
@param string[] $texts list of texts for each column
@param array $colors A list of color names to use for each column. use empty string for default
@return string
@throws Exception
Displays text in multiple word wrapped columns