2

Hi is there a PHP function to build a string of alpha characters from numerals?

e.g

1 = a
2 = b
3 = c

etc?

2
  • each character has an unique ascii code: Take a look at this: asciitable.com I think you need code to convert ascii code to character am i right? Commented Dec 8, 2011 at 12:29
  • 1
    there is no way to detect if you have 26, it is BF or Z Commented Dec 8, 2011 at 12:29

3 Answers 3

5

You can use the chr() function combined with an offset for this e.g.:

$offset = 96;
echo chr(1 + $offset);
echo chr(2 + $offset);
echo chr(3 + $offset);
Sign up to request clarification or add additional context in comments.

Comments

3

Depending on what you want in the end, strtr [docs] might be sufficient:

$str = strtr('1234567890', 'abcdefghij', $str);

Comments

0

Iterate the string and use ord() to convert from characters to numeric values. Then apply the necessary offset. If you want to convert from numeral to characters, use chr().

1 Comment

if I understand the question correctly, he wants to change numbers into letters, not the other way around

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.