As you exit this loop:
while (gmp_strval($divmod[0]) >= 58)
{
$divmod = divmod($divmod[0], 58);
$out = $alphabet[gmp_strval($divmod[1])] . $out;
}
$divmod[0] = 4
But you never use that value. You exit the loop and print out the conversion that you've done so far, but you never calculate the final $alphabet[gmp_strval($divmod[0])]
Oh you're right. I don't understand why, though?
I'm porting it from
https://github.com/bkkcoins/misc/blob/master/hexwif/hexwifand it's pretty much the exact same code, isn't it?
Either way, thanks a lot!