ord

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

addcslashes

addslashes

bin2hex

chop

chr

chunk_split

convert_uudecode

convert_uuencode

count_chars

crc32

crypt

echo

explode

fprintf

get_html_translation_table

hebrev

hebrevc

hex2bin

html_entity_decode

htmlentities

htmlspecialchars

htmlspecialchars_decode

implode

join

lcfirst

levenshtein

localeconv

ltrim

md5

md5_file

metaphone

nl_langinfo

nl2br

number_format

parse_str

print

printf

quoted_printable_decode

quoted_printable_encode

quotemeta

rtrim

setlocale

sha1

sha1_file

similar_text

soundex

sprintf

sscanf

str_contains

str_ends_with

str_getcsv

str_ireplace

str_pad

str_repeat

str_replace

str_rot13

str_shuffle

str_split

str_starts_with

str_word_count

strcasecmp

strchr

strcmp

strcoll

strcspn

strip_tags

stripcslashes

stripos

stripslashes

stristr

strlen

strnatcasecmp

strnatcmp

strncasecmp

strncmp

strpbrk

strpos

strrchr

strrev

strripos

strrpos

strspn

strstr

strtok

strtolower

strtoupper

strtr

substr

substr_compare

substr_count

substr_replace

trim

ucfirst

ucwords

vfprintf

vprintf

vsprintf

wordwrap

PHP

Home Menu