<?
/**
 * Function to calculate base36 values from a number. Very 
 * useful if you wish to generate IDs from numbers. 
 * 
 * @param $value The number 
 * @param $base The base to be applied (16, 36 or 64)
 * @return The calculated string 
 * @author Shashank Tripathi (shanx@shanx.com)
 * @version 0.1 - Let me know if something doesnt work
 * 
 */
 
function base36($value, $base) 
{
    $baseChars = 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'
                     );
    $remainder = 0;
    $newval = "";
    
    while ( $value > 0 ) 
    {
        $remainder = $value % $base;
        $value = ( ($value - $remainder)/ $base );
        $newval .= $baseChars[$remainder];
    }
    return strrev($newval);
    
}
echo "The string for 46655, for instance, is " . base36(46655, 36);
?>