Home >>PHP String Functions >PHP chr() Function
The PHP chr() function is used in PHP to change any specified ASCII value in to a single character string.
This chr() function is an in-built function of PHP.
We pass any ASCII value as the parameter of this function and in return we get a string of characters from the given specified ASCII value.
These ASCII value can be in Octal, Decimal or any other values. As the Output, we get the string corresponding to the number which we have passed in the parameter.
Syntax :
string chr( $asciiValue)
Let's see this chr() with an example:
<html> <body> <?php echo chr(45) . "<br>";// Using decimal value echo chr(99) . "<br>"; echo chr(69) . "<br>"; echo chr(072) . "<br>";// Using octal value echo chr(054) . "<br>"; echo chr(0x25) . "<br>"; //Using hex value ?> </body> </html>
More Examples:-
<html> <body> <?php $str1 = chr(42); $str2 = chr(61); $str3 = chr(43); echo("(55 $str1 2) $str3 40 $str2 150"); ?> </body> </html>
<html> <body> <?php $str1 = chr(80); $str2 = chr(72); $str3 = chr(0x48); $str4 = chr(0x50); echo("We love $str1$str2$str1")."<br>"; echo("We love $str4$str3$str4"); ?> </body> </html>