PHP chr() function
Syntax
chr ( integer ) ;
Parameter | Description |
Integer | Any integer 0-255 (Required) |
Definition
It returns the single character string representation of the ASCII byte-value.
Usage
chr() function is used to find the ASCII character of any integer. For example 64 represent @ symbol.
Example of chr function
<?php echo chr(35); ?>
- Example
- Run
You can directly pass the integer into the chr function as shown in above.
More example of chr function
<?php $str = chr(65); $str1 = chr(120); echo " The ASCII character of 65 : " . $str ."
"; echo "The ASCII character of 120 : " . $str1."
"; ?>
- Example
- Run
Print all ASCII character
<?php for($i=50;$i<=70;$i++) { echo $i." ".chr($i)."
"; } ?>&
Output
50 2
51 3
52 4
53 5
54 6
55 7
56 8
57 9
58 :
59 ;
60 <
61 =
62 >
63 ?
64 @
65 A
66 B
67 C
68 D
69 E
70 F
51 3
52 4
53 5
54 6
55 7
56 8
57 9
58 :
59 ;
60 <
61 =
62 >
63 ?
64 @
65 A
66 B
67 C
68 D
69 E
70 F
According to the above example we are printing twenty integer and corresponding ASCII character.
We can print all the integer and corresponding ASCII character by initialization of $i=0 and condition $i<=255.