The ord()
function returns the equivalent ASCII value.
PHP ord() Function has the following syntax.
int ord ( string str )
str
is the string value to convert.
The ord()
function returns the equivalent ASCII value.
The chr()
function does the opposite of ord()
.
It takes an ASCII value and returns the equivalent character.
Check the character ASCII value
<?PHP
$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.