columns in a text file
From: red (groups2_at_reenie.org)
Date: 01/30/05
- Next message: WindAndWaves: "Re: google and php session IDs"
- Previous message: Ken: "Re: Post_max_size"
- Next in thread: Geoff Berrow: "Re: columns in a text file"
- Reply: Geoff Berrow: "Re: columns in a text file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 30 Jan 2005 19:18:53 GMT
I have two columns of strings of various lengths.
I want the second column to be straight, so I need to find the correct
number of tabs between the two columns for each row.I don't mind
starting with a wide column with a preset number of tabs and adjusting
it statically to fit my data, so I don't need to get the length of the
longest string in the first column before I start.
Through trial and error, I have an algorithm that seems to work. There's
a pattern in there but I don't see the logic. Does anyone have a
more graceful algorithm for this, the way it should be done ?
for each row, I use this:
echo tabber($col1_value, 5);
echo col2_value;
function tabber($col1, $tabs=1){
$result=$col1;
$len=strlen($col1);
if($len>28)$tabs+=1;
if($len==22)$tabs+=1;
if($len<1)$tabs-=1;
if($len==7)$tabs-=1;
for($i=$len; $i>0; $i=$i-7)
$tabs=$tabs-1;
for($j=1; $j<$tabs; $j++)
$result.= "\t";
// $result.="_".$len."_".$tabs."_";// adds debug info to column 2
return $result;
}
red
- Next message: WindAndWaves: "Re: google and php session IDs"
- Previous message: Ken: "Re: Post_max_size"
- Next in thread: Geoff Berrow: "Re: columns in a text file"
- Reply: Geoff Berrow: "Re: columns in a text file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|