Posted: Fri Jun 23, 2006 12:20 pm
Yeah, sorry about that.. I adjusted the code without checking it from the one I wrote on my dev box._Thndr wrote:@feyd: Wow that did the trick! I did have to remove the '0' from the bcmod function, because it only seemed to take two arguments. Thanks a lot!
bcmath is used for arbitrary, often well beyond standard integer limits. You can, for instance keep precision of several hundred decimal places or add up numbers that go well beyond 2^32.
Here's the original I wrote:
Code: Select all
function getUserId($str)
{
$x = '0';
$user = strval($str);
$j = strlen($user);
bcscale(0);
$keep = bcpow('2', '32');
for ($i = 0; $i < $j; ++$i)
{
$x = bcmul($x, '101');
$x = bcmod($x, $keep);
$x = bcadd($x, ord(strtolower($user[$i])));
}
return $x;
}