Current Location: Home> Function Categories> chr

chr

Generate single-byte strings from numbers
Name:chr
Category:String
Programming Language:php
One-line Description:Returns a character from the specified ASCII value.

Definition and usage

The chr() function returns a character from the specified ASCII value.

ASCII value can be specified as a decimal value, an octal value, or a hexadecimal value. The octal value is defined as prefixed 0, while the hexadecimal value is defined as prefixed 0x.

Example

Example 1

Return characters from different ASCII values:

 <?php
echo chr ( 61 ) . "<br>" ; // decimal
echo chr ( 061 ) . "<br>" ; // Octal value
echo chr ( 0x61 ) . "<br>" ; // Hexadecimal value
?>

Try it yourself

Example 2

Use the octal value 046 to add the ASCII character:&.

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

Try it yourself

Example 3

Use decimal values ​​43 and 61 to add ASCII characters: + and =.

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

Try it yourself

grammar

 chr ( ascii )
parameter describe
ascii Required. ASCII value.
Similar Functions
Popular Articles