PHP chr() Function

PHP timezone_name_get() Function
PHP chop() Function

In this article, you will learn;

  • How to convert ASCII value to chactacter in PHP.

The PHP Chr() function solves this problem and provides the following functionalities.

  • Convert decimal ASCII value to character.
  • Convert Octal ASCII value to chracter. In this case the value starts with 0.
  • Converts Hexadecimal ASCII value to character. In this case the value starts with 0x.
ASCII stands for American Standard Code for Information Interchange.

What is the syntax of the CHR() function in PHP?

chr(ascii)
ParameterDescription
asciiThe ASCII value (decimal, Octal or Hexadecimal) – Required
PHP chr(ascii) method

Example of the CHR() function

Example 1. In this example, we pass the decimal, octal and hexadecimal values to the CHR() function respectively and observed their output using echo.

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

Example 2. In this example, we get the character from the CHR() function and used it in the string.

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

Example 3. In this example, we represent another conversion of ASCII value to the corresponding character.

<?php
$str = chr(43);
$str_2 = chr(61);
echo("2 $str 2 $str_2 4");
?>

ASCII Table

ASCII Table
ASCII TABLE https://www.asciitable.com/
PHP timezone_name_get() Function
PHP chop() Function

Stay up-to-date about PHP!

We don’t spam!

en English
X
Scroll to Top