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