Mailinglisten-Archive |
Hi Sebastian,
> > z.B.: 162332455867748196059487746156453429162392759
> > http://www.uris.de/test/div/shorty.class.php
> ganz cool eigentlich, jedoch wurde der punkt/komma gekillt.
das passiert _wahlweise_ siehe Link 'mit.Komma' ...
Und hier der 'bereinigte' und getestete Code aus der Mail:
<?php
$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($number) {
global $charset;
$divisor = count($charset);
$result = '';
while ($number > $divisor) {
$x = bcmod($number, $divisor);
$number = bcdiv($number, $divisor);
$result .= $charset[$x];
}
$result .= $charset[$number];
return $result;
}
function decode($string) {
global $charset;
$faktor = count($charset);
$result = 0;
for ($i = 0; $i < strlen($string); $i++) {
$X = array_keys($charset, $string[$i]);
$result = bcadd($result, bcmul($X[0], bcpow($faktor, $i)));
}
return $result;
}
?>
m. b. G. Norbert
_____________________
normal: 02686-987103
Notruf: 0163-3613642
---------------------
e.o.m.
php::bar PHP Wiki - Listenarchive