Latest web development tutorials

PHP chr () function

PHP String Reference PHP String Reference

Examples

The value returned from a different character ASCII:

<?php
echo chr(52) . "<br>"; // Decimal value
echo chr(052) . "<br>"; // Octal value
echo chr(0x52) . "<br>"; // Hex value
?>

Running instance »

Definition and Usage

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

ASCII values ​​may be specified as decimal values, octal values ​​or hexadecimal values. Octal value is defined as with leading zeros, hexadecimal value is defined as with pre 0x.


grammar

chr( ascii )

参数 描述
ascii 必需。ASCII 值。

technical details

return value: Returns the specified character.
PHP version: 4+


More examples

Example 1

Octal value 046 to add ASCII characters: &.

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

Running 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");
?>

Running instance »


PHP String Reference PHP String Reference