PHP chr() Function
The PHP chr() function is used to generate a single byte string from a number. In another words we can say that it returns a character from specified ASCII value.
Syntax:
string chr ( int $bytevalue );
Parameter | Description | Required/Optional |
---|---|---|
ascii | An ASCII value | Required |
Example 1
<?php
$char =52;
echo "Your character is :".$char;
echo "<br>"."By using 'chr()' function your value is: ".chr($char);// decimal Value
?>
Output
Your character is :52
By using 'chr()' function your value is: 4
Example 2
<?php
$char =052;
echo "Your character is :".$char;
echo "<br>"."By using 'chr()' function your value is: ".chr($char); // Octal Value
?>
Output
Your character is :42
By using 'chr()' function your value is: *
Example 3
<?php
echo "Your character is :0x52";
echo "<br>"."By using 'chr()' function your value is: ".chr(0x52); // Hex value
>?
Output
Your character is :0x52
By using 'chr()' function your value is: R
Example 4
<?php
$str = chr(43); // +
$str2 = chr(61); // =
echo("2 $str 2 $str2 4");
>?
Output
2 + 2 = 4
Given above program in which the ASCII value of chr(43) is '+' and chr(61) is '=' converted .