PHP 8 reference · String Functions

PHP ord() Function

Return the value (0 to 255) of the first byte of a string, such as 65 for "A". The reverse of chr().

PHP 8 Since 4.0

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

ord(string $character): int

Parameters

ParameterDescription
character A string; only its first byte is read.

Return value

An integer from 0 to 255.

Examples

Character codesTry it yourself
<?php
echo ord("A"), " ", ord("a"), " ", ord("0"), "\n";

Output

65 97 48
Bytes vs code pointsTry it yourself
<?php
echo ord("é"), "\n";            // the first of two UTF-8 bytes
echo mb_ord("é"), "\n";         // the Unicode code point

Output

195
233

Version history

VersionChange
PHP 4.0Added

In other languages

Was this page helpful?