No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

Rechercher une fonction PHP

chr

(PHP 4, PHP 5, PHP 7)

chrGenerate a single-byte string from a number

Description

chr ( int $bytevalue ) : string

Returns a one-character string containing the character specified by interpreting bytevalue as an unsigned integer.

This can be used to create a one-character string in a single-byte encoding such as ASCII, ISO-8859, or Windows 1252, by passing the position of a desired character in the encoding's mapping table. However, note that this function is not aware of any string encoding, and in particular cannot be passed a Unicode code point value to generate a string in a multibyte encoding like UTF-8 or UTF-16.

This function complements ord().

PHP: chr - Manual Home of Manuel PHP  Contents Haut

Parameters

bytevalue

An integer between 0 and 255.

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

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

PHP: chr - Manual Home of Manuel PHP  Contents Haut

Return Values

A single-character string containing the specified byte.

PHP: chr - Manual Home of Manuel PHP  Contents Haut

Examples

Example #1 chr() example

<?php
// Assumes the string will be used as ASCII or an ASCII-compatible encoding

$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

Example #3 Building a UTF-8 string from individual bytes

<?php
declare(encoding='UTF-8');
$str chr(240) . chr(159) . chr(144) . chr(152);
echo 
$str;
?>

The above example will output:


🐘

PHP: chr - Manual Home of Manuel PHP  Contents Haut

See Also

Find a PHP function
Error Infobrol

Can not display this page of the Infobrol website

Type of error (18-01)

Unknown format specifier "&"

Please try again in a few minutes…

Return to the home page




Steph