PHP chr()Functions
Examples
Return characters from different ASCII values:
<?php
echo chr(52) . "<br>"; // Decimal value
echo chr(052) . "<br>"; // Octal value
echo chr(0x52) . "<br>"; // Hex value
?>
echo chr(52) . "<br>"; // Decimal value
echo chr(052) . "<br>"; // Octal value
echo chr(0x52) . "<br>"; // Hex value
?>
Run Example »
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 leading 0, and hexadecimal values are defined with a leading 0x.
Syntax
chr(ascii)
| Parameter | Description |
|---|---|
| ascii | Required. The 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!");
?>
$str = chr(046);
echo("You $str me forever!");
?>
Run Example »
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");
?>
$str = chr(43);
$str2 = chr(61);
echo("2 $str 2 $str2 4");
?>
Run Example »
PHP String Reference Manual Other Extensions