PHP chr() Function

❮ PHP String Reference

Example

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
?>
Try it Yourself »

Definition and Usage

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

The ASCII value can be specified in decimal, octal, or hex values. Octal values are defined by a leading 0, while hex values are defined by a leading 0x.


Syntax

chr(ascii)

Parameter Values

Parameter Description
ascii Required. An ASCII value


Technical Details

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

More Examples

Example

Using the octal value 046 to add the ASCII Character: &.

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

Example

Using the decimal values 43 and 61 to add the ASCII Characters: + and =.

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

❮ PHP String Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.