I\'m coding an url shortener function for a project in which I\'m learning php, here is the code (btw I suppose that global here is not a good thing to do :P):<
How about this:
function shorten_int($id){
$hex = base_convert(id, 10, 16);
$base64 = base64_encode(pack('H*', $hex));
//$base64 = str_replace("/", "_", $base64); // remove unsafe url chars
//$base64 = str_replace("+", "-", $base64);
//$base64 = rtrim($base64, '='); // Remove the padding "=="
$replacePairs = array('/' => '_',
'+' => '-',
'=' => '');
$base64 = strtr($base64, $replacePairs); // optimisation
return $base64;
}