Mailinglisten-Archive |
Hi,
>> das sieht im ersten Moment gut aus. Was mich aber wundert ist
>> z.B. das pow(). Kann das wirklich mit 18stelligen Integerwerten
>> umgehen? Diese langen Zahlen waren bei mir das größte Problem.
>>
>> Ich bekomme mit Deinen Funktionen jedenfalls folgendes:
>>
>> decode("uVHHtL1");
>> 47112279699
>>
>> encode(47112279699);
>> VHHtL
das erste Zeichen geht verlohren weil für PHP
47112279699 % 63 -> -14
ist. Wie gesagt, große Zahlen sind problematisch...
Jetzt habe ich da meine Version mit Deinem Array zusammen gebracht:
$charset = array(
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z',
'_'
);
function encode($val)
{
global $charset;
$divisor = count($charset);
$ret = "";
for ($x=0; $x<7; $x++) {
$valn = intval($val / $divisor);
$part = $val - $valn * $divisor;
$val = $valn;
$ret .= $charset[$part];
}
return ($ret);
}
function decode($string)
{
global $charset;
$divisor = count($charset);
$mul = 1;
$rval = 0;
for ($x=0; $x<7; $x++) {
$part = substr($string,$x,1);
$part = array_keys($charset, "$part");
$part = $part[0];
$rval += $part*$mul;
$mul *= $divisor;
}
return $rval;
}
echo decode("uVHHtL1")."\n\n";
// 109635781908
echo encode(109635781908)."\n\n";
// uVHHtL1
array_keys() ist da aber noch irgendwie seltsam :|
array_keys($charset, "L");
lieferte das:
Array
(
[0] => 0
[1] => 47
)
Nachdem ich die erste Zeile des Arrays in ' gesetzt habe, ging es
Gruß, Reinhold
--
Reinhold Jordan
WWW: http://reinhold.bachrain.de Mail: reinhold at bachrain.de
"The first time you'll get a Microsoft product, that doesn't suck,
will be the day they start producing vacuum cleaners." (unknown)
php::bar PHP Wiki - Listenarchive