PHP chr() Function

Example

Returns characters from different ASCII values:

<?php
echo chr(61) . "<br>"; // Decimal
echo chr(061) . "<br>"; // Octal value
echo chr(0x61) . "<br>"; // Hexadecimal value
?>

Run Instance

Definition and Usage

The chr() function returns a character from the specified ASCII value.

ASCII values can be specified as decimal values, octal values, or hexadecimal values. Octal values are defined with a prefix of 0, while hexadecimal values are defined with a prefix of 0x.

Syntax

chr(ascii)
Parameter Description
ascii Required. ASCII value.

Technical Details

Return Value: Returns the specified character.
PHP Version: 4+

More Examples

Example 1

Use octal value 046 to add ASCII character: &.

<?php
$str = chr(046);
echo("You $str me forever!");
?>

Run Instance

Example 2

Use decimal values 43 and 61 to add ASCII characters: + and =.

<?php
$str = chr(43);
$str2 = chr(61);
echo("2 $str 2 $str2 4");
?>

Run Instance