How to make alignment on console in php

前端 未结 7 779
慢半拍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:50

    The CLIFramework table generator helps you get the job done very easily and it supports text alignment, text color, background color, text wrapping, text overflow handling.. etc

    Here is the tutorial: https://github.com/c9s/CLIFramework/wiki/Using-Table-Component

    Sample code: https://github.com/c9s/CLIFramework/blob/master/example/table.php

    use CLIFramework\Component\Table\Table;
    
    $table = new Table;
    $table->setHeaders([ 'Published Date', 'Title', 'Description' ]);
    $table->addRow(array( 
        "September 16, 2014",
        "Title",
        "Description",
        29.5
    ));
    $table->addRow(array( 
        "November 4, 2014",
        "Hooked: How to Build Habit-Forming Products",
        ["Why do some products capture widespread attention whil..."],
        99,
    ));
    echo $table->render();
    

提交回复
热议问题