2017 © Pedro Peláez
 

library php-to-ascii-table

A PHP library to generate plain text tables.

image

malios/php-to-ascii-table

A PHP library to generate plain text tables.

  • Saturday, April 1, 2017
  • by malios
  • Repository
  • 1 Watchers
  • 8 Stars
  • 574 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 50 % Grown

The README.md

php-to-ascii-table

A small PHP library for generating plain text tables., (*1)

example table, (*2)

Getting Started

Prerequisites

  • PHP >= 7
  • ext-mbstring
  • Optionally Install php-ds extension (Recommended).

Installation

Install via composer:, (*3)

$ composer require malios/php-to-ascii-table

Usage

<?php
    $builder = new \AsciiTable\Builder();

    $builder->addRows([
        [
            'Order No' => 'A0001',
            'Product Name' => 'Intel CPU',
            'Price' => 700.00,
            'Quantity' => 1
        ],
        [
            'Order No' => 'A0002',
            'Product Name' => 'Hard disk 10TB',
            'Price' => 500.00,
            'Quantity' => 2
        ],
        [
            'Order No' => 'A0003',
            'Product Name' => 'Dell Laptop',
            'Price' => 11600.00,
            'Quantity' => 8
        ],
        [
            'Order No' => 'A0004',
            'Product Name' => 'Intel CPU',
            'Price' => 5200.00,
            'Quantity' => 3
        ]
    ]);

    $builder->addRow([
        'Order No' => 'A0005',
        'Product Name' => 'A4Tech Mouse',
        'Price' => 100.00,
        'Quantity' => 10
    ]);

    $builder->setTitle('Product List');

    echo $builder->renderTable();


    // Show only some fields

    $builder->showColumns(['Order No', 'Product Name', 'Quantity']);

    echo $builder->renderTable();

Build table from objects

You can build table form any object that implements JsonSerializable interface., (*4)

<?php

    class Person implements \JsonSerializable 
    {
        private $name;

        private $age;

        public function __construct(string $name, int $age) {
            $this->name = $name;
            $this->age = $age;
        }

        public function jsonSerialize()
        {
            return [
                'name' => $this->name,
                'age' => $this->age
            ];
        }
    }

    $builder = new \AsciiTable\Builder();

    $builder->addRow(new Person('John', 25));
    $builder->addRow(new Person('Bill', 30));

    echo $builder->renderTable();

Contributing

All contributors are welcome. You can open a new issue or submit a pull request. See CONTRIBUTING.md for details., (*5)

License

This project is licensed under the MIT License - see the LICENSE.md file for details., (*6)

The Versions

01/04 2017

dev-master

9999999-dev

A PHP library to generate plain text tables.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mehmed Aliosman

php table ascii plain text table

01/04 2017

v1.0.1.x-dev

1.0.1.9999999-dev

A PHP library to generate plain text tables.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mehmed Aliosman

php table ascii plain text table

01/04 2017

v1.0.1

1.0.1.0

A PHP library to generate plain text tables.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mehmed Aliosman

php table ascii plain text table

26/03 2017

v1.0.0

1.0.0.0

A PHP library to generate plain text tables.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mehmed Aliosman

php table ascii plain text table