PHP | ord() Function
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:
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 116
Below 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"); ?> |
Output:
116
Program 2:
<?php // PHP program to illustrate the ord() function // ASCII value of 'G' is printed echo ord("Geeksforgeeks"); ?> |
Output:
71
Reference:
http://php.net/manual/en/function.ord.php
Recommended Posts:
- How to get the function name from within that function using JavaScript ?
- PHP | dir() Function
- D3.js | d3.min() function
- PHP | exp() Function
- PHP Ds\Set get() Function
- D3.js | d3.set.add() Function
- p5.js | int() function
- CSS | rgb() Function
- PHP | pow( ) Function
- CSS | hsl() Function
- D3.js | d3.sum() function
- D3.js | d3.mean() function
- PHP | Ds\Set contains() Function
- p5.js | hex() function
- p5.js | str() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



