Jump to content

Function that Converts Numeric Into Alphanumic


aeroguy

Recommended Posts

Hi i am looking for a function that converts a numeric value, ie 0, 1, 2 ,3 into a four digit alpha number equivalent ie aaaa, aaab, aaac. Not sure how you would go about doing it when you reach double and triple digits.

 

the values should be the following for the alpha numeric

 

0 a

1 b

2 c

3 d

4 e

5 f

6 g

7 h

8 i

9 j

10 k

11 l

12 m

13 n

14 o

15 p

16 q

17 r

18 s

19 t

20 u

21 v

22 w

23 x

24 y

25 z

26 A

27 B

28 C

29 D

30 E

31 F

32 G

33 H

34 I

35 J

26 K

27 L

28 M

29 N

30 O

31 P

32 Q

33 R

34 S

35 T

36 U

37 V

38 W

39 X

40 Y

41 Z

42 0

43 1

44 2

45 3

46 4

47 5

48 6

49 7

50 8

51 9

look at ASCII Table

 

ascii_table.jpg

 

you will see small 'a' starts at 97 dec

you will also see they are in order small 'z' = 122

 

so the math for 0 = a would be

 

Now look at A-Z starts from 65 to 90

if(($number + 97) >= 97 && ($number + 97) <= 122) {
echo chr($number+97); //will show a,b,c,..,x,y,z.
} elseif((($number-26)+65) >= 65 && (($number-26)+65) <= 90) {
echo chr(($number-26)+65); //will show A,B,C...X,Y,Z
}
//do same for numbers got bored to finish it
}

 

idk if php function exists but it's sure as hell easy to code this yourself. takes no more then a minute honestly

you could make an array of the keys and values you want, like this:

<?php
$letters = array(0 =>"a",1=>"b",2=>"c",3=>"etc");
?>

 

 

then if you have 4 numbers, like 3102 you would just do:

<?php

$alpha_string = $letters[3].$letters[1].$letters[0].$letters[2];
echo $alpha_string;

?>

then if you have 4 numbers, like 3102 you would just do:

<?php

$alpha_string = $letters[3].$letters[1].$letters[0].$letters[2];
echo $alpha_string;

?>

 

Yes, but then like the OP already mentioned what if 31 represents 31? followed by 0 and 2

 

$alpha_string = $letters[31].$letters[0].$letters[2];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.