FREE Web Template Download
HTML CSS JAVASCRIPT SQL PHP BOOTSTRAP JQUERY ANGULARJS TUTORIALS REFERENCES EXAMPLES Blog
 

PHP chr() Function

PHP String Reference 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
?>
Run example »

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 Description
ascii Required. An ASCII value

Technical Details

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

More Examples

Example 1

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

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

Example 2

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");
?>
Run example »


PHP String Reference PHP String Reference