ord()
ord() — Convert the first byte of a string to a value between 0 and 255.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Interprets the binary value of the first byte of character as an unsigned integer between 0 and 255.
Signature
ord(string $character): int
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $character | string | A character. |
Return value
An integer between 0 and 255.
Example
A runnable snippet:
$str = "\n"; if (ord($str) == 10) { echo "The first character of \$str is a line feed.\n"; }
Changelog
| Version | Change |
|---|---|
| 8.5.0 | Passing a string which is not a single byte is now deprecated. |
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page ord() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.