Letter: M
ord(): 77
chr(): M
Match: yes
Tab code: 9
How It Works
Start with a letter."M" is the input character.
ord → code.ord("M") returns 77.
chr → letter.chr(77) returns "M" again.
Control chars too.chr(9) is a tab; ord reads it back as 9.
Frequently Asked Questions
chr() converts an integer code point into a single-character string. For example, chr(65) returns "A" because 65 is the ASCII code for uppercase A.
string chr(int $codepoint). You pass an integer (typically an ASCII or Unicode code point) and receive a one-character string.
chr() converts a number to a character (code → char). ord() does the reverse—it returns the code point of the first byte of a string (char → code). They are inverse operations for single-byte characters.
For standard ASCII, use 0–127. chr() also accepts 128–255 for extended byte values. In PHP 7.1+, chr() supports Unicode code points beyond 255 when the value maps to a valid character.
A common pattern is a loop from 65 to 90 calling chr($i) to generate letters A through Z. This avoids typing each letter manually and is widely used in alphabet pattern tutorials.