Location: PHPKode > scripts > extensive > extensive/extensive.php
<?
// This class'goal is return a number in extensive format in english language
// Autor : Pablo Dall'Oglio (hide@address.com)
// Date :  Wednesday, 16, 2001

class extensive
{

  // return 3 by 3 number extensive
  function three_extensive($cVALOR)
  {
    $aUNID   = array(""," ONE "," TWO "," THREE "," FOUR "," FIVE "," SIX "," SEVEN "," EIGHT "," NINE ");
    $aDEZE   = array("","   "," TWENTY"," THIRTY"," FORTY"," FIFTY"," SIXTY"," SEVENTY"," EIGHTY"," NINETY ");
    $aCENT   = array("","ONE HUNDRED AND","TWO HUNDRED AND","THREE HUNDRED AND","FOUR HUNDRED AND","FIVE HUNDRED AND","SIX HUNDRED AND","SEVEN HUNDRED AND","EIGHT HUNDRED AND","NINE HUNDRED AND");
    $aEXC    = array(" TEN "," ELEVEN "," TWELVE "," THIRTEEN "," FOURTEEN "," FIFTEEN "," SIXTEEN "," SEVENTEEN "," EIGHTEEN "," NINETEEN ");
    $nPOS1   = substr($cVALOR,0,1);
    $nPOS2   = substr($cVALOR,1,1);
    $nPOS3   = substr($cVALOR,2,1);
    $cCENTE  = $aCENT[($nPOS1)];
    $cDEZE   = $aDEZE[($nPOS2)];
    $cUNID   = $aUNID[($nPOS3)];

    if (substr($cVALOR,0,3) == "100")
    { $cCENTE = "ONE HUNDRED "; }

    if (substr($cVALOR,1,1) == "1")
    {  $cDEZE = $aEXC[$nPOS3];
      $cUNID = "";
    }

    $cRESULT = $cCENTE . $cDEZE . $cUNID;
    $cRESULT = substr($cRESULT,0,strlen($cRESULT)-1);
    return $cRESULT;
  }

  // main function that control return of class
  function byextensive($cVALOR, $lMOEDA)
  {
    //pict 999.999.999,99

    $zeros = "000.000.000,00";
    $cVALOR = number_format($cVALOR,2);
    $cVALOR = substr($zeros,0,strlen($zeros)-strlen($cVALOR)) . $cVALOR;


    if ($lMOEDA)
    {
      $cMOEDA_SINGULAR = " DOLLAR";
      $cMOEDA_PLURAL   = " DOLLARS";
    }
    else
    {
      $cMOEDA_SINGULAR = "";
      $cMOEDA_PLURAL   = "";
    }

    //cVALOR  = transform( nVALOR, "@ZE 999,999,999.99");
    //$cRETURN = substr($cVALOR,0,3) . substr($cVALOR,4,3) . substr($cVALOR,8,3);

    $cMILHAO = $this->three_extensive(substr($cVALOR,0,3)) . ( (substr($cVALOR,0,3)>1) ? ' MILLIONS' : '' );
    $cMILHAR = $this->three_extensive(substr($cVALOR,4,3)) . ( (substr($cVALOR,4,3)>0) ? ' THOUSAND' : '' );
    $cUNIDAD = $this->three_extensive(substr($cVALOR,8,3)) . ( ($nVALOR==1) ? $cMOEDA_SINGULAR : $cMOEDA_PLURAL);
    $cCENTAV = $this->three_extensive("0" . substr($cVALOR,12,2)) . ((substr($cVALOR,12,2)>0) ? " CENTS" : "");

    $cRETURN = $cMILHAO . ((strlen(trim($cMILHAO))<>0 && strlen(trim($cMILHAR))<>0) ? ", " : "") .
              $cMILHAR . ((strlen(trim($cMILHAR))<>0 && strlen(trim($cUNIDAD))<>0) ? ", " : "") .
              $cUNIDAD . ((strlen(trim($cUNIDAD))<>0 && strlen(trim($cCENTAV))<>0) ? ", " : "") .
              $cCENTAV;
    return $cRETURN;
  }
}
?>
Return current item: extensive