October 2005
Intermediate to advanced
372 pages
11h 35m
English
ord()
int ord ( string str )The ord()
function takes a string and returns the equivalent ASCII value. For example:
$mystr = "ASCII is an easy way for computers to work with strings\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";
}That code should output The second letter in the string is S. The chr() function does the opposite of ord(): it takes an ASCII value and returns the equivalent character.