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//from   w  w w.  j a  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.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions