PHP ord() Function
In this chapter you will learn:
- Definition for PHP ord() Function
- Syntax for PHP ord() Function
- Parameter for PHP ord() Function
- Return for PHP ord() Function
- Note for PHP ord() Function
- Example - Check the character ASCII value
Definition
The ord()
function returns the equivalent ASCII value.
Syntax
PHP ord() Function has the following syntax.
int ord ( string str )
Parameter
str
is the string value to convert.
Return
The ord()
function returns the equivalent ASCII value.
Note
The chr()
function does the opposite of ord()
.
It takes an ASCII value and returns the equivalent character.
Example
Check the character ASCII value
<?PHP/*from ja v a2 s .com*/
$mystr = "A demo from java2s.com\n";
if (ord($mystr{1}) == 83) {
print "The second letter in the string is S\n";
} else {
print "The second letter is not S\n";
}
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP parse_str() Function
- Syntax for PHP parse_str() Function
- Parameter for PHP parse_str() Function
- Return for PHP parse_str() Function
- Example - Parse URL parameter to variables
- Example - Put value to an array
Home » PHP Tutorial » PHP String Functions