Use base_convert($number, 10, 36)will not relate to a-zanything other than a-zas indicated in the question. Custom features required.
int , , base-62 (62 0-9, az AZ).
:
<?php
function toBase62 ($dec) {
if ($dec == 0)
return "0";
$values = 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", "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"
);
$neg = $dec < 0;
if ($neg)
$dec = 0 - $dec;
$chars = array();
while ($dec > 0) {
$val = $dec % 62;
$chars[] = $values[$val];
$dec -= $val;
$dec /= 62;
}
while (count($chars) < 6)
$chars[] = '0';
$rv = implode( '' , array_reverse($chars) );
return $neg ? "-$rv" : $rv;
}
$permalink = toBase62($id);
?>
:
<?php
function base62ToInt ($str) {
if ( ! preg_match('/^\-?[0-9A-Za-z]+$/', $str) )
return FALSE;
if ($str == "0" )
return 0;
$values = 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", "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"
);
$values = array_flip($values);
$chars = str_split($str);
$neg = $chars[0] == '-';
if ($neg)
array_shift($chars);
$val = 0;
$i = 0;
while ( count($chars) > 0 ) {
$char = array_pop($chars);
$val += ($values[$char] * pow(62, $i) );
++$i;
}
return $neg ? 0 - $val : $val;
}
$id = base62ToInt($permalink);
?>