Convert the first byte of a string to a value between 0 and 255
Syntax
ord ( string $string ) : int
Parameters
string
A character.
Return
An integer between 0 and 255.
Examples
1 · string
<? $string = "Hello"; $return = ord($string); echo $return; ?>
72
2 · 1
<? echo ord("\n") . PHP_EOL; echo ord(" ") . PHP_EOL; echo ord(",") . PHP_EOL; echo ord(".") . PHP_EOL; echo ord("0") . PHP_EOL; echo ord("9") . PHP_EOL; echo ord("A") . PHP_EOL; echo ord("Z") . PHP_EOL; echo ord("a") . PHP_EOL; echo ord("z") . PHP_EOL; ?>
10 32 44 46 48 57 65 90 97 122
3 · 2
<? $string = "🐘"; for ($i = 0; $i < strlen($string); ++$i) { $byte = substr($string, $i); echo 'byte ' . $i . ' has value ' . ord($byte) . PHP_EOL; } ?>
byte 0 has value 240 byte 1 has value 159 byte 2 has value 144 byte 3 has value 152