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.


The syntax of the chr() function:



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

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


The output of the above example is:


To understand the above example, you should have the basic knowledge of the following PHP topics:

All PHP Programs

Comments and Discussions!

Load comments ↻

Copyright © 2024 All rights reserved.