Voting

: max(two, zero)?
(Example: nine)

The Note You're Voting On

lrirwin at alum dot wustl dot edu
3 years ago
I'm converting 30 year old code and needed a string TAB function:

//tab function similar to TAB used in old BASIC languages
//though some of them did not truncate if the string were
//longer than the requested position
function tab($instring="",$topos=0){
if(strlen($instring)<$topos){
$result=str_pad($instring,$topos-1," ",STR_PAD_RIGHT);
}else{
$result=substr($instring,0,$topos-1);
}
return $result;
}

$pline="String with this tab to 50 and";
$tline=tab($pline,50)."finish it.";
echo $tline.PHP_EOL;
$pline="101010101020202020203030303030404040404050505050506060606060";
$tline=tab($pline,50)."finish it.";
echo $tline.PHP_EOL;

//Results in this output:
//String with this tab to 50 and finish it.
//1010101010202020202030303030304040404040505050505finish it.

<< Back to user notes page

To Top