Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

ord()

Read the unsigned value of the first byte, in the range 0–255.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

ord(string $character): int

Read the unsigned value of the first byte, in the range 0–255. Remaining bytes are ignored, so a multibyte UTF-8 character yields its first encoded byte rather than its Unicode code point. Pass nonempty text when a first byte is required. In PHP 8.4 the empty string and a single NUL byte both yield 0. Check the input length to distinguish them.

Signature

ord(string $character): int

Example output

[65,195,0,255]
[[0,0],[0,1]]

Examples

<?php
echo json_encode([ord("AB"),ord("\u{00E9}"),ord("\0"),ord("\xFF")]);
echo PHP_EOL,json_encode([[ord(""),strlen("")],[ord("\0"),strlen("\0")]]);

Result

[65,195,0,255]
[[0,0],[0,1]]

Sources