Ver Mensaje Individual
  #5 (permalink)  
Antiguo 30/04/2010, 11:36
maxwellxp
 
Fecha de Ingreso: abril-2010
Mensajes: 143
Antigüedad: 14 años
Puntos: 0
Respuesta: necesito funcion que convierta numeros a letra

Código PHP:
Ver original
  1. if ((int)$ent === 0) return 'Cero ' . $fin;
  2.    $tex = '';
  3.    $sub = 0;
  4.    $mils = 0;
  5.    $neutro = false;
  6.    
  7.    while ( ($num = substr($ent, -3)) != '   ') {
  8.      
  9.       $ent = substr($ent, 0, -3);
  10.       if (++$sub < 3 and $fem) {
  11.          $matuni[1] = 'uno';
  12.          $subcent = 'as';
  13.       }else{
  14.          $matuni[1] = $neutro ? 'un' : 'uno';
  15.          $subcent = 'os';
  16.       }
  17.       $t = '';
  18.       $n2 = substr($num, 1);
  19.       if ($n2 == '00') {
  20.       }elseif ($n2 < 21)
  21.          $t = ' ' . $matuni[(int)$n2];
  22.       elseif ($n2 < 30) {
  23.          $n3 = $num[2];
  24.          if ($n3 != 0) $t = 'i' . $matuni[$n3];
  25.          $n2 = $num[1];
  26.          $t = ' ' . $matdec[$n2] . $t;
  27.       }else{
  28.          $n3 = $num[2];
  29.          if ($n3 != 0) $t = ' y ' . $matuni[$n3];
  30.          $n2 = $num[1];
  31.          $t = ' ' . $matdec[$n2] . $t;
  32.       }
  33.      
  34.       $n = $num[0];
  35.       if ($n == 1) {
  36.          $t = ' ciento' . $t;
  37.       }elseif ($n == 5){
  38.          $t = ' ' . $matunisub[$n] . 'ient' . $subcent . $t;
  39.       }elseif ($n != 0){
  40.          $t = ' ' . $matunisub[$n] . 'cient' . $subcent . $t;
  41.       }
  42.      
  43.       if ($sub == 1) {
  44.       }elseif (! isset($matsub[$sub])) {
  45.          if ($num == 1) {
  46.             $t = ' mil';
  47.          }elseif ($num > 1){
  48.             $t .= ' mil';
  49.          }
  50.       }elseif ($num == 1) {
  51.          $t .= ' ' . $matsub[$sub] . 'ón';
  52.       }elseif ($num > 1){
  53.          $t .= ' ' . $matsub[$sub] . 'ones';
  54.       }  
  55.       if ($num == '000') $mils ++;
  56.       elseif ($mils != 0) {
  57.          if (isset($matmil[$sub])) $t .= ' ' . $matmil[$sub];
  58.          $mils = 0;
  59.       }
  60.       $neutro = true;
  61.       $tex = $t . $tex;
  62.    }
  63.    $tex = $neg . substr($tex, 1) . $fin;
  64.    return ucfirst($tex);
  65. }
  66. ?>