PHP 8 reference · String Functions
PHP chr() Function
Return the one-byte character for a value from 0 to 255, such as "A" for 65. The reverse of ord().
PHP 8 Since 4.0
Syntax
chr(int $codepoint): string
Parameters
| Parameter | Description |
|---|---|
codepoint |
A value from 0 to 255 (others wrap around). |
Return value
A one-byte string.
Examples
<?php
echo chr(65), chr(66), chr(67), "\n";
Output
ABC
<?php
$letters = "";
for ($i = 0; $i < 5; $i++) {
$letters .= chr(ord("a") + $i);
}
echo $letters, "\n";
echo mb_chr(233), "\n"; // Unicode code points need mb_chr()
Output
abcde é
Version history
| Version | Change |
|---|---|
| PHP 4.0 | Added |
In other languages
chr()· PythonString.fromCharCode()· JavaScriptString.fromCodePoint()· JavaScript
Related
ord()· Return the value (0 to 255) of the first byte of a string, such as 65 for "A". The reverse of chr().- PHP Strings · tutorial