No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

Rechercher une fonction PHP

ord

(PHP 4, PHP 5, PHP 7)

ordConvert the first byte of a string to a value between 0 and 255

Description

ord ( string $string ) : int

Interprets the binary value of the first byte of string as an unsigned integer between 0 and 255.

If the string is in a single-byte encoding, such as ASCII, ISO-8859, or Windows 1252, this is equivalent to returning the position of a character in the character set's mapping table. However, note that this function is not aware of any string encoding, and in particular will never identify a Unicode code point in a multi-byte encoding such as UTF-8 or UTF-16.

This function complements chr().

PHP: ord - Manual Home of Manuel PHP  Contents Haut

Parameters

string

A character.

PHP: ord - Manual Home of Manuel PHP  Contents Haut

Return Values

An integer between 0 and 255.

PHP: ord - Manual Home of Manuel PHP  Contents Haut

Examples

Example #1 ord() example

<?php
$str 
"\n";
if (
ord($str) == 10) {
    echo 
"The first character of \$str is a line feed.\n";
}
?>

Example #2 Examining the individual bytes of a UTF-8 string

<?php
declare(encoding='UTF-8');
$str "🐘";
for ( 
$pos=0$pos strlen($str); $pos ++ ) {
 
$byte substr($str$pos);
 echo 
'Byte ' $pos ' of $str has value ' ord($byte) . PHP_EOL;
}
?>

The above example will output:


Byte 0 of $str has value 240
Byte 1 of $str has value 159
Byte 2 of $str has value 144
Byte 3 of $str has value 152

PHP: ord - Manual Home of Manuel PHP  Contents Haut

See Also

Find a PHP function
Error Infobrol

Can not display this page of the Infobrol website

Type of error (18-01)

Unknown format specifier "&"

Please try again in a few minutes…

Return to the home page




Steph