The chr() and ord() functions in PHP are used to convert between ASCII values and their corresponding characters. They are commonly used for string manipulation and character-level operations.
chr() converts an ASCII number into its character representation.ord() returns the ASCII value of the first character in a string.chr(int $ascii) → characterord(string $char) → integer
// Convert ASCII value to character
<?php
$char = chr(65);
echo $char;
?>
The output will be A because ASCII value 65 corresponds to the character A.
// Convert character to ASCII value
<?php
$ascii = ord("A");
echo $ascii;
?>
The output will be 65 because A has an ASCII value of 65.
You can loop through ASCII values (65–90) using chr() to dynamically generate the English alphabet.
chr() for ASCII-based character generation.ord() to analyze or compare characters.