1<?php 2 3namespace Mpdf\Conversion; 4 5class DecToAlpha 6{ 7 8 public function convert($valor, $toUpper = true) 9 { 10 // returns a string from A-Z to AA-ZZ to AAA-ZZZ 11 // OBS: A = 65 ASCII TABLE VALUE 12 if (($valor < 1) || ($valor > 18278)) { 13 return '?'; //supports 'only' up to 18278 14 } 15 16 $c2 = $c3 = ''; 17 18 $c1 = 64 + $valor; // 1 letter (up to 26) 19 if ($valor > 702) { // 3 letters (up to 18278) 20 $c1 = 65 + floor(($valor - 703) / 676); 21 $c2 = 65 + floor((($valor - 703) % 676) / 26); 22 $c3 = 65 + floor((($valor - 703) % 676) % 26); 23 } elseif ($valor > 26) { // 2 letters (up to 702) 24 $c1 = (64 + (int) (($valor - 1) / 26)); 25 $c2 = (64 + ($valor % 26)); 26 if ($c2 === 64) { 27 $c2 += 26; 28 } 29 } 30 31 $alpha = chr($c1); 32 33 if ($c2 !== '') { 34 $alpha .= chr($c2); 35 } 36 37 if ($c3 !== '') { 38 $alpha .= chr($c3); 39 } 40 41 if (!$toUpper) { 42 $alpha = strtolower($alpha); 43 } 44 45 return $alpha; 46 } 47 48} 49