125 of 410 menu

The ord Function

The ord function returns the ASCII code of a character. It accepts a single character or a whole string as a parameter (in which case it returns the code of its first character).

Syntax

ord(string $character): int

Example

Let's find out the code of the character 'a':

<?php echo ord('a'); ?>

Code execution result:

97

Example

Let's output the code of the first character of the string:

<?php echo ord('abcde'); ?>

Code execution result:

97

See Also

  • the chr function,
    which returns a character by its code
byenru