• Here’s the zeroise() function SPAM is currently using:
    function zeroise($number, $threshold) { // function to add leading zeros when necessary
    $l=strlen($number);
    if ($l<$threshold)
    for ($i=0; $i<($threshold-$l); $i=$i+1) { $number='0'.$number; }
    return $number;
    }

    I wrote this little piece of code, which should do the same, but is much smaller and faster.
    function zeroise($number, $treshold) {
    return sprintf("%0".$treshold."s", $number);
    }

    Good? Bad? Let me know.

Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Better zeroise() function.’ is closed to new replies.