Representing binary data as Hex numbers has been a standard for a while, but using only sixteen printable characters when there's many more "safe" ASCII characters possible has lead to other sorts of numbering systems. This class allows you to define your own "number" progression and encode/decode integers through it. The Radix of the conversion used is the length of the string passed to the class, making it very customizable. Several standard character sets (many from RFC 4648) are included, or pass your own custom character string.
This implementation uses the BC Math PHP extension if it's installed to convert very large integers successfully.
<?php
// Hex to Base64
echo radix_convert(Radix::HEX_UPPER, Radix::DECIMAL, 'FF')."\n";
// Hex test
$r = new Radix('0123456789abcdef');
$str = 'ffffffffff';
for ($i=0; $i<10; $i++) {
echo $str." => ";
$rs = $r->decode($str);
echo $rs." => ".$r->encode($rs)."\n";
$str .= 'f';
}
// High-radix test
$r = new Radix(Radix::BASE_94);
for ($i=0; $i<10; $i++) {
$rand = bcpow(rand(1, 9999999999), 5);
echo $rand." => ";
$rs = $r->encode($rand);
echo $rs." => ".$r->decode($rs)."\n";
}