Ver Mensaje Individual
  #3 (permalink)  
Antiguo 23/07/2008, 14:06
Avatar de josefferhn
josefferhn
 
Fecha de Ingreso: agosto-2007
Ubicación: Tegucigalpa, Fco Morazan
Mensajes: 27
Antigüedad: 16 años, 8 meses
Puntos: 0
Respuesta: Script que "Lea Numeros" y los escriba en Texto ???

Que tal. prueba con este script:

Código PHP:
<?
/*
 * PHP Freaks Code Library
 * http://www.phpfreaks.com/quickcode.php
 *
 * Title: Convert a number to words in spanish
 * Version: 1.0
 * Author: Alejandro Ordiales aka(alejandro)
 * Date: Thursday, 08/05/2004 - 09:20 PM
 *
 * 
 *
 * NOTICE: This code is available from PHPFreaks.com code Library.
 *         This code is not Copyrighted by PHP Freaks. 
 *
 *         PHP Freaks does not claim authorship of this code.
 *
 *         This code was submitted to our website by a user. 
 *
 *         The user may or may not claim authorship of this code.
 *
 *         If there are any questions about the origin of this code,
 *         please contact the person who submitted it, not PHPFreaks.com!
 *
 *         USE THIS CODE AT YOUR OWN RISK! NO GUARANTEES ARE GIVEN!
 *
 * SHAMELESS PLUG: Need WebHosting? Checkout WebHost Freaks:
 *                 http://www.webhostfreaks.com
 *                 WebHosting by PHP Freaks / The Web Freaks!
*/


// *    Description / Example:
// *    
// *    This function returns a string in spanish from a numeric value. Just pass a  float number like 34565.78 and will return the string  (TREINTA Y CUATRO MIL QUINIENTOS SESENTA Y CINCO PESOS 78/100).
// *    Based on the code written by Wayne Herbert.

?>

<?
// Title: Numeric to spanish words
// Author: Wayne Herbert Modified by Alejandro Ordiales.
// ** Thank you Wayne **
// Date: Aug 05, 2004


// Code Snipplet:

//***************************************************************
// this function converts an amount into alpha words in spanish
// the mexican way.  Pass it a float.
// Example:  $123.77 = (CIENTO VEINTITRES PESOS 77/100)
// works up to 999,999,999.99 - Great for checks
// Modify lines 69 and 73 to use other currency (pesos)
//***************************************************************
//***************************************************************
// Esta funcion convierte una cantidad a letras en español
// como lo hacemos en mexico.  Pasa un numero con o sin decimales
// Ejemplo:  $123.77 = (CIENTO VEINTITRES PESOS 77/100)
// funciona desde 1 hasta 999,999,999.99 - Util para cheques o 
// tiendas virtuales. Modifica las lineas 69 and 73 para usar 
// otra moneda
//***************************************************************

function makewords($numval
{
$moneystr "**"// Variables Iniciales
// Millions
$milval = (integer)($numval 1000000);
if(
$milval == 1) {
  
$moneystr .= "Un millon";
  }
if(
$milval 1) {
  
$moneystr .= getwords($milval) . " millones";
  }  
// thousands
$workval $numval - ($milval 1000000); // get rid of millions
$thouval = (integer)($workval 1000);
if(
$thouval 0) {
  
$workword getwords($thouval);
  if (
$moneystr == "") {
    
$moneystr $workword " mil";
    } else {
    
$moneystr .= " " $workword " mil";
    }
  }
// handle all the rest of the money
$workval $workval - ($thouval 1000); // get rid of thousands
$tensval = (integer)($workval);
if (
$moneystr == 0) {
  if (
$tensval 0) {
    
$moneystr .= getwords($tensval);
    } else {
    
$moneystr .= " ";//Cero
    
}
  } else {
// non zero values in hundreds and up 
  
$workword getwords($tensval);
  
$moneystr .= " " $workword;
  }
// plural or singular
$workval = (integer)($numval);
if (
$workval == 1) {
  
$moneystr .= " Con ";
  } else {
  
$moneystr .= " Con ";
  }
// do the pennies - use printf so that we get the
// same rounding as printf
$workstr sprintf("%3.2f",$numval); // convert to a string
$intstr substr($workstr,strlen 22);
$workint = (integer)($intstr);
if (
$workint == 0)
  {
  
$moneystr .= "00/100 **";
  } else {
  
$moneystr .= $workint."/100 **";
  }

// done - let's get out of here!
return $moneystr;
}

//*************************************************************
// this function creates word phrases in the range of 1 to 999.
// pass it an integer value
//*************************************************************
function getwords($workval) {
$numwords = array(
  
=> "un",
  
=> "dos",
  
=> "tres",
  
=> "cuatro",
  
=> "cinco",
  
=> "seis",
  
=> "siete",
  
=> "ocho",
  
=> "nueve",
  
10 => "diez",
  
11 => "once",
  
12 => "doce",
  
13 => "trece",
  
14 => "catorce",
  
15 => "quince",
  
16 => "dieciseis",
  
17 => "diecisiete",
  
18 => "dieciocho",
  
19 => "diecinueve",
  
20 => "veinte",
  
30 => "treinta",
  
40 => "cuarenta",
  
50 => "cincuenta",
  
60 => "sesenta",
  
70 => "setenta",
  
80 => "ochenta",
  
90 => "noventa");
 
$numpal = array(
  
=> "ciento",
  
=> "doscientos",
  
=> "trescientos",
  
=> "cuatrocientos",
  
=> "quinientos",
  
=> "seiscientos",
  
=> "setecientos",
  
=> "ochocientos",
  
=> "novecientos");

// handle the 100's
$hundval2 = ($workval 100); //if hundval ==1 and hundval2 > 1 {$retstr = "cien"}
$retstr " ";
$hundval = (integer)($workval 100);
if (
$hundval == && $hundval2 == 1) {
  
$retstr "cien";
  }
if (
$hundval == && $hundval2 1) {
  
$retstr "ciento";
  }
if (
$hundval 1) {
  
$retstr .= $numpal[$hundval];
  }
 
// handle units and teens
$workstr "";
$tensval $workval - ($hundval 100); // dump the 100's
$tempval = ((integer)($tensval 10)) * 10;
$unitval $tensval $tempval;
if ((
$tensval 20) && ($tensval 0)) {// do the teens
  
$workstr $numwords[$tensval];
  } else {
// got to break out the units and tens
  
if ($tensval 20 && $tensval 30) {// do the teens
  
$workstr .= " veinti".$numwords[$unitval];
  } else { 
  
$workstr $numwords[$tempval]; // get the tens
  
if ($unitval 0) {
    
$workstr .= " y " $numwords[$unitval];
    }
  }
  }  
// join all the parts together and leave
if ($workstr != "") {
  if (
$retstr != "") {
    
$retstr .= " " $workstr;
    } else {
    
$retstr $workstr;
    }
  } return 
$retstr;
}

/* #Esta parte del codigo es para que inicie la conversion.
$valor = 225859;
echo "Valor a Convertir: ".$valor."<br>";
$resultado = makewords($valor);
echo strtoupper($resultado);
*/
?>
Ok, esto es todo para mandar a llamar la funcion, haces lo siguiente:

$valor = 15000;
$Resultado = makewords($valor);

Espero te sirva