PHP Tutorial - PHP ord() Function






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
$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.