function num2alpha($n) //數字轉英文(0=>A、1=>B、26=>AA...以此類推)
{
for($r = ""; $n >= 0; $n = intval($n / 26) - 1)
$r = chr($n%26 + 0x41) . $r;
return $r;
}
function alpha2num($a) //英文轉數字(A=>0、B=>1、AA=>26...以此類推)
{
$l = strlen($a);
$n = 0;
for($i = 0; $i < $l; $i++)
$n = $n*26 + ord($a[$i]) - 0x40;
return $n-1;
}
No comments:
Post a Comment