Documentation

TableFormatter
in package

Class TableFormatter

Output text in multiple columns

Tags
author

Andreas Gohr andi@splitbrain.org

license

MIT

Table of Contents

Properties

$border  : string
$colors  : Colors
$max  : int

Methods

__construct()  : mixed
TableFormatter constructor.
format()  : string
Displays text in multiple word wrapped columns
getBorder()  : string
The currently set border (defaults to ' ')
getMaxWidth()  : int
Width of the terminal in characters
setBorder()  : mixed
Set the border. The border is set between each column. Its width is added to the column widths.
setMaxWidth()  : mixed
Set the width of the terminal to assume (in characters)
calculateColLengths()  : array<string|int, int>
Takes an array with dynamic column width and calculates the correct width
getTerminalWidth()  : int
Tries to figure out the width of the terminal
pad()  : string
Pad the given string to the correct length
strlen()  : int
Measures char length in UTF-8 when possible
substr()  : string
wordwrap()  : string

Properties

Methods

__construct()

TableFormatter constructor.

public __construct([Colors|null $colors = null ]) : mixed
Parameters
$colors : Colors|null = null

format()

Displays text in multiple word wrapped columns

public format(array<string|int, int> $columns, array<string|int, string> $texts[, array<string|int, mixed> $colors = array() ]) : string
Parameters
$columns : array<string|int, int>

list of column widths (in characters, percent or '*')

$texts : array<string|int, string>

list of texts for each column

$colors : array<string|int, mixed> = array()

A list of color names to use for each column. use empty string for default

Tags
throws
Exception
Return values
string

getBorder()

The currently set border (defaults to ' ')

public getBorder() : string
Return values
string

getMaxWidth()

Width of the terminal in characters

public getMaxWidth() : int

initially autodetected

Return values
int

setBorder()

Set the border. The border is set between each column. Its width is added to the column widths.

public setBorder(string $border) : mixed
Parameters
$border : string

setMaxWidth()

Set the width of the terminal to assume (in characters)

public setMaxWidth(int $max) : mixed
Parameters
$max : int

calculateColLengths()

Takes an array with dynamic column width and calculates the correct width

protected calculateColLengths(array<string|int, mixed> $columns) : array<string|int, int>

Column width can be given as fixed char widths, percentages and a single * width can be given for taking the remaining available space. When mixing percentages and fixed widths, percentages refer to the remaining space after allocating the fixed width

Parameters
$columns : array<string|int, mixed>
Tags
throws
Exception
Return values
array<string|int, int>

getTerminalWidth()

Tries to figure out the width of the terminal

protected getTerminalWidth() : int
Return values
int

terminal width, 0 if unknown

pad()

Pad the given string to the correct length

protected pad(string $string, int $len) : string
Parameters
$string : string
$len : int
Return values
string

strlen()

Measures char length in UTF-8 when possible

protected strlen(mixed $string) : int
Parameters
$string : mixed
Return values
int

substr()

protected substr(string $string[, int $start = 0 ][, int|null $length = null ]) : string
Parameters
$string : string
$start : int = 0
$length : int|null = null
Return values
string

wordwrap()

protected wordwrap(string $str[, int $width = 75 ][, string $break = "\n" ][, bool $cut = false ]) : string
Parameters
$str : string
$width : int = 75
$break : string = "\n"
$cut : bool = false
Tags
link
http://stackoverflow.com/a/4988494
Return values
string

        
On this page

Search results