PHP chr() Function
In this chapter you will learn:
- Definition for PHP chr() Function
- Syntax for PHP chr() Function
- Parameter for PHP chr() Function
- Return for PHP chr() Function
- Note for PHP chr() Function
- Example - Convert number to character
Definition
To convert an ASCII number to its character equivalent, use the chr()
function.
chr()
takes an ASCII value and returns the character equivalent, if there is one.
chr()
has the following format.
Syntax
PHP chr() Function has the following syntax.
string chr ( int ascii_val )
Parameter
ascii_val
is the value to convert.
Return
PHP chr() function returns character from ascii number.
Note
The ord()
function does the opposite of chr()
:
it takes a string and returns the equivalent ASCII value.
Example
Convert number to character
<?PHP
$letter = chr(100);
print "ASCII number 100 is equivalent to $letter\n";
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP chunk_split() Function
- Syntax for PHP chunk_split() Function
- Parameter for PHP chunk_split() Function
- Return for PHP chunk_split() Function
- Note for PHP chunk_split() Function
- Example - Split the string after each character and add a "." after each split
- Example - Split the string after each sixth character and add a "..." after each split
Home » PHP Tutorial » PHP String Functions