chr(): character from the specified ASCII value

Convert a byte value to a one-character string

chr() returns a one-byte string for the supplied integer value. It is useful for byte-oriented work and ASCII examples; Unicode code points need a Unicode-aware approach.

echo chr(65); // A
echo chr(35); // #
chr() function to print ASCII characters , here are some examples.
$string = "Let us print a variable " . chr(36) . "my_var";echo $string; // Let us print a variable $my_var
Output ( char(36) is $ )
Let us print a variable $my_var 
Here are additional printable ASCII examples:
echo "Let us print hash " . chr(35); // Let us print hash #
echo PHP_EOL;echo "Less than " . chr(60); // Less than <
We can use ord function to get ASCII value of any character
For an HTML table, display printable ASCII bytes (32–126) and escape each character before inserting it into markup. Control bytes are omitted because they are not printable.
// Printable ASCII range only: control bytes 0–31 and 127 are omitted.
echo '<table class="table table-sm"><tbody>';for ($i = 32; $i <= 126; $i++) {
    echo '<tr><td>' . $i . '</td><td>'
        . htmlspecialchars(chr($i), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8')
        . '</td></tr>';}echo '</tbody></table>';
The printable-ASCII table is generated below:
ByteCharacter
32
33!
34"
35#
36$
37%
38&
39'
40(
41)
42*
43+
44,
45-
46.
47/
480
491
502
513
524
535
546
557
568
579
58:
59;
60<
61=
62>
63?
64@
65A
66B
67C
68D
69E
70F
71G
72H
73I
74J
75K
76L
77M
78N
79O
80P
81Q
82R
83S
84T
85U
86V
87W
88X
89Y
90Z
91[
92\
93]
94^
95_
96`
97a
98b
99c
100d
101e
102f
103g
104h
105i
106j
107k
108l
109m
110n
111o
112p
113q
114r
115s
116t
117u
118v
119w
120x
121y
122z
123{
124|
125}
126~

Example 2: Creating Special Character Symbols for HTML Entities

A byte above 127 is not automatically a valid UTF-8 character. In HTML, use an entity or a UTF-8 literal for a copyright symbol; reserve chr() for the appropriate byte-oriented use:

// chr(169) is one byte, not a UTF-8 copyright symbol.
// For an HTML document, output an HTML entity instead:
echo 'Copyright: &copy; 2026';

Example 3: Using *chr()* for Character Ranges

ASCII letter ranges can be generated with a loop:

for ($i = 65; $i <= 90; $i++) {
    echo chr($i) . " "; // A through Z
}

String Functions ord()


Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer