How to make alignment on console in php

前端 未结 7 812
慢半拍i
慢半拍i 2020-12-23 17:06

I am trying to run a script through command prompt in PHP and trying to show the result in tabular form. But due to different character length of words I am not able to show

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-23 17:45

    Your best option is to use the Pear Package Console_Table ( http://pear.php.net/package/Console_Table/ ).

    To use - on a console you need to install the pear package, running:

    pear install Console_Table
    

    this should download the package and install. You can then use a sample script such as:

    require_once 'Console/Table.php';
    
    $tbl = new Console_Table();
    $tbl->setHeaders(
        array('Language', 'Year')
    );
    $tbl->addRow(array('PHP', 1994));
    $tbl->addRow(array('C',   1970));
    $tbl->addRow(array('C++', 1983));
    
    echo $tbl->getTable();
    

提交回复
热议问题