Formatting plain text file
Formatting plain text file
am 31.07.2009 00:19:31 von Skip Evans
Hey all,
Am I brain fading or what? I'm so used to formatting text in
tables for HTML display I can't think of how to do it for a
plain text file.
I just need to create a columned table of names and addresses
type stuff... sprintf?
--
====================================
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://bigskypenguin.com
------------------------------------
Those of you who believe in
telekinesis, raise my hand.
-- Kurt Vonnegut
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Formatting plain text file
am 31.07.2009 00:21:55 von List Manager
Skip Evans wrote:
> Hey all,
>
> Am I brain fading or what? I'm so used to formatting text in tables for
> HTML display I can't think of how to do it for a plain text file.
>
> I just need to create a columned table of names and addresses type
> stuff... sprintf?
or a little str_pad on each variable...
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Formatting plain text file
am 31.07.2009 00:29:32 von Skip Evans
Jim Lucas wrote:
> Skip Evans wrote:
>> Hey all,
>>
>> Am I brain fading or what? I'm so used to formatting text in tables for
>> HTML display I can't think of how to do it for a plain text file.
>>
>> I just need to create a columned table of names and addresses type
>> stuff... sprintf?
>
> or a little str_pad on each variable...
>
Sure, that will do it. But isn't there some way to construct
formatted tables similar to HTML?
--
====================================
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://bigskypenguin.com
------------------------------------
Those of you who believe in
telekinesis, raise my hand.
-- Kurt Vonnegut
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Formatting plain text file
am 31.07.2009 01:05:30 von Robert Cummings
Skip Evans wrote:
> Jim Lucas wrote:
>> Skip Evans wrote:
>>> Hey all,
>>>
>>> Am I brain fading or what? I'm so used to formatting text in tables for
>>> HTML display I can't think of how to do it for a plain text file.
>>>
>>> I just need to create a columned table of names and addresses type
>>> stuff... sprintf?
>> or a little str_pad on each variable...
>>
>
> Sure, that will do it. But isn't there some way to construct
> formatted tables similar to HTML?
You can use a combination of wordwrap(), str_pad(), and swathe of
judicious (but simplistic) math :)
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Formatting plain text file
am 31.07.2009 03:20:30 von B
On 07/30/2009 06:29 PM, Skip Evans wrote:
> Jim Lucas wrote:
>> Skip Evans wrote:
>>> Hey all,
>>>
>>> Am I brain fading or what? I'm so used to formatting text in tables for
>>> HTML display I can't think of how to do it for a plain text file.
>>>
>>> I just need to create a columned table of names and addresses type
>>> stuff... sprintf?
>>
>> or a little str_pad on each variable...
>>
>
> Sure, that will do it. But isn't there some way to construct formatted
> tables similar to HTML?
>
>
Are you thinking of a CSV file that you can open in a spreadsheet prog?
Or, do you literally mean a plaintext file with columns? For the latter,
you'd need to measure the max char length of each "column" for every
line in the file, then go back and print each line using str_pad().
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Formatting plain text file
am 31.07.2009 03:31:22 von kranthi
//assuming you have a 2d matrix $table
$table = array(
array("c11", "c12", "c13"),
array("c21", "c22", "c23")
);
foreach($table as $rows) {
$row = vsprintf(str_repeat("%-10s", count($rows)), $rows);
echo "{$row}
\n";
}
wont this do ?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php