Starting with PHP 5.3.2, GMP supports databases up to 62 (previously there were only 36), so the brianreavis proposal was very close. I think the easiest answer to your question is:
function base62hash($source, $chars = 22) { return substr(gmp_strval(gmp_init(md5($source), 16), 62), 0, $chars); }
The conversion from base-16 to base-62 obviously has advantages in space. A typical 128-bit MD5 hash is 32 characters in hexadecimal, but in base-62 it is only 22. If you store hashes in a database, you can convert them to a raw binary file and save even more space (16 bytes for MD5 )
Since the resulting hash is just a string representation, you can just use substr if you only need a little bit of it (as the function does).
Synchro
source share