Skip to content

Commit 90403a5

Browse files
authored
Updated Readme
Updated the readme file with useful information, methods and examples
1 parent 5bc42f6 commit 90403a5

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

README.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,59 @@
1-
# array-to-text-php
1+
# Array to Text Table
2+
*forked from https://gist.github.com/tony-landis/31477*
3+
24
This PHP class can convert an array into ascii text table.
5+
6+
## Example Usage:
7+
8+
```
9+
require_once ('ArrayToTextTable.php');
10+
11+
$data = array(
12+
array('company'=>'AIG', 'id'=>1, 'balance'=> '-$99,999,999,999.00'),
13+
array('company'=>'Wachovia', 'id'=>2, 'balance'=> '-$10,000,000.00'),
14+
array('company'=>'HP', 'id'=>3, 'balance'=> '$555,000.000.00'),
15+
array('company'=>'IBM', 'id'=>4, 'balance'=> '$12,000.00')
16+
);
17+
18+
$renderer = new ArrayToTextTable($data);
19+
$renderer->showHeaders(true);
20+
$renderer->render();
21+
```
22+
### Output of above example
23+
```
24+
+----------+----+---------------------+
25+
| COMPANY | ID | BALANCE |
26+
+----------+----+---------------------+
27+
| AIG | 1 | -$99,999,999,999.00 |
28+
| Wachovia | 2 | -$10,000,000.00 |
29+
| HP | 3 | $555,000.000.00 |
30+
| IBM | 4 | $12,000.00 |
31+
+----------+----+---------------------+
32+
```
33+
34+
35+
## Useful Methods:
36+
37+
#### `render` *default: false*
38+
You can catch the output of the render with `render(true)`
39+
```
40+
$output = $renderer->render(true);
41+
```
42+
43+
#### `showHeaders` *default: false*
44+
Show the headers using the key values of the array for the titles
45+
```
46+
$renderer->showHeaders(true);
47+
```
48+
49+
#### `setMaxWidth` *default: 30*
50+
Set the maximum width (number of characters) per column before truncating
51+
```
52+
$renderer->setMaxWidth(30);
53+
```
54+
55+
#### `setMaxHeight` *default: 2*
56+
Set the maximum height (number of lines) per row before truncating
57+
```
58+
$renderer->setMaxHeight(30);
59+
```

0 commit comments

Comments
 (0)