Name
ord()
Synopsis
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.
Get PHP in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.