The ord() function in PHP is an inbuild function which is a very important function to get the ASCII value as a returned value. This is a function which considers a character string as a parameter and then as mentioned return value comes out to be the ASCII value of the first character of this string which is defined. Php ord function basically takes a single parameter from the string and is a mandatory parameter to get the ASCII value as a return value. Association of the string function with ord function also has a significance in it.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
Syntax:
ord(String)
The syntax flow is as follows the ord function is a part of String References in PHP which is used to get the first character of the string is passed as a parameter. Also, String is the most important parameter of the ord function both are somehow dependent on each other. The string is the most required parameter and is used to get an ASCII value associated with the string and especially the first character of the string.
PHP ord is the function that is part of the PHP versions with PHP 4, PHP 5, and PHP 7. It converts the first byte of a string to a value lying between 0 and 255.
A binary value first gets interpreted and then the first byte of the string given as an input of string works as an unsigned integer between 0 and 255.
Only if in case the string is a single byte encoded string then it only it will return a value equivalent to return the position of a character in the entire mapping of the set as value present in the set’s mapping table. But a condition applies that the function is not aware of the string encoding and particularly it will not identify a Unicode code as a point in a multi-byte encoded values.
chr is also a complimentary of ord() function it also takes string as an input that too with a single parameter containing some characters in the string by returning a one-character string again with a single byte encoding by interpreting byte value as an unsigned integer. Also, this can be used to create a one-character string in a single byte encoding to pass some code points or values which can also generate a string with multibyte encoding. Parameters belonging to the function are the same as integer values between 0 and 255. Contrary to this the return type becomes a single character string containing the specified byte. These mentioned traits show that it is totally complimentary to the ord() function in PHP.
ASCII values are the best companions for the ord() function of PHP as it helps in referring and pointing to ASCII values and ASCII table values pointing to it. It is also one of the important parameters of PHP ord() function.
mb_ord() is a subset function of the ord() function which works in a way that helps in getting the code point of character. If the condition gets satisfies then returns the value otherwise it returns a value as false as a return type. String and single encoding type string are the parameters being passed to the md_ord() function which is a subset of the ord() function.
Note:the md_ord function being stated is not fully documented and available as part of documentation for the PHP versions. It is just the parameters and the return type being defined and described but actual dependencies and follow ups is not yet present in the official documentation or website for PHP particularly for md_ord function.Below are the examples of the PHP ord() function:
This program illustrates the ord() function returning the value of We from the input of string as welcome in the given program with ord() function.
Code:
Output:
This program illustrates the use of the ord function to represent the string being passed as a parameter to the ord function for its return type to return the integer value and ascii value of the string which is e is returned with a value of 101.
Code :
Output:
This program illustrates the use of the ord function to represent the string being passed as a parameter to the ord function for its return type to return the integer value and ascii value of the string which is g is returned with a value of 103
Code :
Output:
A program to represent that the first character of the string being passed is a line feed using ord() function.
Code :
Output:
A program to represent the ord function if the scope of the declaration is not global instead if it is local then the output will be represented as an output.
Code :
Output:
A program to represent the ord function if the scope of the declaration is not declared and an empty string is passed whose output stands as illustrated below.
Code :
Output:
PHP ord() function only supports for PHP 4, PHP5 and PHP 7 versions. It is a pre-defined function that blends with the string references of the PHP language very nicely and helps in providing end-users a better functionality and feature for string and Unicode-defined strings.
This is a guide to the PHP ord(). Here we discuss the Introduction to PHP ord() Function and how it works along with examples as well as Code Implementation. You can also go through our other suggested articles to learn more-
以上是PHP ord()的詳細內容。更多資訊請關注PHP中文網其他相關文章!