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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

chr(int $codepoint): string

Parameters

ParameterDescription
codepoint A value from 0 to 255 (others wrap around).

Return value

A one-byte string.

Examples

Build charactersTry it yourself
<?php
echo chr(65), chr(66), chr(67), "\n";

Output

ABC
Loop over lettersTry it yourself
<?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

VersionChange
PHP 4.0Added

In other languages

Was this page helpful?