Skip to content

Instantly share code, notes, and snippets.

@lenybernard
Created November 6, 2013 10:06
Show Gist options
  • Select an option

  • Save lenybernard/7333685 to your computer and use it in GitHub Desktop.

Select an option

Save lenybernard/7333685 to your computer and use it in GitHub Desktop.
num to alphanumeric
/**
* Give 1 => A
* 2 => B
* etc
**/
public function num2alpha($number) {
$number--;
$result = '';
for ($i = 1; $number >= 0 && $i < 10; $i++) {
$result = chr(0x41 + ($number % pow(26, $i) / pow(26, $i - 1))) . $result;
$number -= pow(26, $i);
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment