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

phpord(string $character): int

Example

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

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

Code execution result:

php97

Example

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

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

Code execution result:

php97

See Also

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