Re: How to format CLI tabular data?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Look into sprintf().  I believe it has whitespace formatting codes that are 
wonderfully suited to this case.  (They're derived from C, where the printf() 
routine is used quite frequently for that sort of screen output.)

On Monday 08 October 2007, Robert Cummings wrote:
> On Mon, 2007-10-08 at 15:59 -0700, Daevid Vincent wrote:
> > I write many CLI scripts in PHP to clean up DB records, etc via crontab
> > scripts. Often though, I implement command line switches to 'debug' or
> > see various data as a precaution before actually purging.
> >
> > Perl has some neat tools built in to format tabular data:
> > http://www.usenix.org/publications/perl/perl08.html
> >
> > Does PHP have any tools like this? I'd prefer not to pull in some PEAR
> > package or other bloat, but I'll take what I can get if it actually works
> > well. I was hoping there are some tips/tricks to show simple tabular
> > data:
> >
> > i.e.:
> >
> > # foo.php --showgroups
> >
> > ==================================
> >               Groups
> > ==================================
> > Name:     Expires:     Date:
> > --------  ------------ -----------
> > groupA        3 hours   2007-10-08
> > groupBeta    10 hours   2007-11-10
> > groupC        1 week    2007-12-31
> >
> >
> > notice basic things like alignment,
> > length of data (as in 'tabs' won't work), etc.
>
> Looks like something you could whip up in half an hour.
>
> Cheers,
> Rob.
> --
> ...........................................................
> SwarmBuy.com - http://www.swarmbuy.com
>
>     Leveraging the buying power of the masses!
> ...........................................................


-- 
Larry Garfield			AIM: LOLG42
larry@xxxxxxxxxxxxxxxx		ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux