Loader

chr

Returns a one-character string containing the character specified by ascii. This function complements ord(). Test chr online.

string chr ( int $ascii )

PHP Documentation by the PHP Documentation Group


chr

(PHP 4, PHP 5, PHP 7)

chrReturn a specific character

Description

string chr ( int $ascii )

Returns a one-character string containing the character specified by ascii.

This function complements ord().

Parameters

ascii

The extended ASCII code.

Values outside the valid range (0..255) will be bitwise and'ed with 255, which is equivalent to the following algorithm:

while ($ascii < 0) {
    $ascii += 256;
}
$ascii %= 256;

Return Values

Returns the specified character.

Examples

Example #1 chr() example

<?php
$str 
"The string ends in escape: ";
$str .= chr(27); /* add an escape character at the end of $str */

/* Often this is more useful */

$str sprintf("The string ends in escape: %c"27);
?>

Example #2 Overflow behavior

<?php
echo chr(-159), chr(833), PHP_EOL;
?>

The above example will output:

aA

See Also


PHP Documentation

Copyright © 1997 - 2016 by the PHP Documentation Group. This material may be distributed only subject to the terms and conditions set forth in the Creative Commons Attribution 3.0 License or later. A copy of the Creative Commons Attribution 3.0 license is distributed with this manual. The latest version is presently available at » http://creativecommons.org/licenses/by/3.0/.