Home »
PHP
PHP chr() function with example
By IncludeHelp Last updated : December 27, 2023
PHP chr() function
The chr() function is used to get the character from a given ASCII code. ASCII value can be in decimal format, octal format by following 0 (zero), and hexadecimal format by following 0x.
Syntax
The syntax of the chr() function:
chr(ASCII_value);
Parameters
The parameters of the chr() function:
- ASCII_value: It accepts ASCII value in number.
Return Value
The return value of this method is string, it returns corresponding character.
Sample Input/Output
Input: 65
Output: 'A'
Input: 0x41
Output: 'A'
Example of PHP chr() Function
<?php
echo (chr(65)."\n"); //ASCII value of 'A' in decimal
echo (chr(0101)."\n"); //ASCII value of 'A' in octal
echo (chr(0x41)."\n"); //ASCII value of 'A' in hex
?>
Output
The output of the above example is:
A
A
A
To understand the above example, you should have the basic knowledge of the following PHP topics: