PHP ord() Function
Last Updated :
21 Jun, 2023
Improve
The ord() function is a inbuilt function in PHP that returns the ASCII value of the first character of a string. This function takes a character string as a parameter and returns the ASCII value of the first character of this string.
Syntax:
PHP
Output:
php
Output:
int ord($string)Parameter: This function accepts a single parameter $string. This is a mandatory parameter from which we get an ASCII value. Return value: This function returns an integer value which represents the ASCII value of the first character in the string passed to this function as a parameter. Examples:
Input : Geeksforgeeks Output : 71 Explanation: The ASCII value of G is 71 Input : twinkle Output : 116 Explanation: The ASCII value of t is 116Below programs illustrate the ord() function in PHP: Program 1:
<?php
// PHP program to illustrate the ord() function
// ASCII value of 't' is printed.
echo ord("twinkle");
?>
116Program 2:
<?php
// PHP program to illustrate the ord() function
// ASCII value of 'G' is printed
echo ord("Geeksforgeeks");
?>
71Reference: http://php.net/manual/en/function.ord.php