mb_ord()
mb_ord() — Get Unicode code point of character.
Built-in function of PHP 8.5. The manual lists it as available in PHP 7 >= 7.2.0, 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
Returns the Unicode code point value of the given character.
Signature
mb_ord(string $string, ?string $encoding = null): int|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $string | string | A string |
| $encoding | ?string | The encoding parameter is the character encoding. If it is omitted or null, the internal character encoding value will be used. |
Return value
The Unicode code point for the first character of string or false on failure.
Example
A runnable snippet:
var_dump(mb_ord("A", "UTF-8")); var_dump(mb_ord("🐘", "UTF-8")); var_dump(mb_ord("\x80", "ISO-8859-1")); var_dump(mb_ord("\x80", "Windows-1252"));
Output:
int(65) int(128024) int(128) int(8364)
Changelog
| Version | Change |
|---|---|
| 8.0.0 | encoding is nullable now. |
| 8.0.0 | Now throws a ValueError if encoding is an invalid encoding. Previously, an E_WARNING was emitted and false was returned. |
See also
mb_internal_encoding(), mb_chr(), ord()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page mb_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.