ord – PHP String Functions

Syntax :

ord ( string );

Description :

The ord() function calculates the ASCII value of first character of a string. This will convert the first byte of a string to a value between 0 and 255


Parameter :

[table caption=”” width=”100%” colwidth=”15%|15%|15%|55%” colalign=”left|lef|lef|left”]
Name, Required /Optional, Value Type, Description

string , Required, String , It is the string for which we have to get an ASCII value from

[/table]


Output :

This will returns an integer between 0 and 255 OR ASCII value as an integer


Related articles : chr(), crc32()md5_file()crypt().


ord() – PHP Functions Example 1 :
<?php
echo ord("t")."<br>";
echo ord("tutor")."<br>";
?>

See below is the output of above code in Web browser.

116
116

ord() – PHP Functions Example 2 :
<?php
$str = "\r";
echo ord($str)."<br>";
if (ord($str) == 13) {
    echo "The first character of a string is a carriage return.\n";
}
?>

See below is the output of above code in Web browser.

13
The first character of a string is a carriage return.

You may also like...