Hola,
Pues, en efecto, hay dos funciones "principales", que, sirven para convertir un número en letras y viceversa. Dichas funciones no las he inventado yo, pero, me he basado en el trabajo de
http://yourls.org/. Por lo demás, como verás este último es un "script PHP" para montarse uno su propio sitio "acortador de URLs", algo así como un WordPress para esta tarea. Yo no me baso completamente en dicho script, pero, sí que he tomado, entre otras cosas, las dos funciones susomentadas. Helas aquí:
Código PHP:
class Min
{
const CHARS_MAP = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
public static function intToStr( $int )
{
$str = '';
$chars = self::CHARS_MAP;
$len = strlen( $chars );
while( $int >= $len )
{
$mod = bcmod( $int, $len );
$int = bcdiv( $int, $len );
$str = $chars[ $mod ] . $str;
}
$str = $chars[ $int ] . $str;
return $str;
}
public static function strToInt( $str )
{
$int = 0;
$chars = self::CHARS_MAP;
$str = strrev( $str );
$baselen = strlen( $chars );
$inputlen = strlen( $str );
for ( $i = 0; $i < $inputlen; $i++ )
{
$index = strpos( $chars, $str[ $i ] );
$int = bcadd( $int, bcmul( $index, bcpow( $baselen, $i ) ) );
}
return $int;
}
}
