ord

int ord(string character) 

Gets the ASCII code for a character.

Returns:

Integer between 0 and 255

Description:

ord() returns the ASCII code for a single character. The value is returned in decimal/base10. To convert the value to hex or octal, use decbin() or dechex(), respectively.

Version:

PHP 3+, PHP 4+

See also:

Other functions that deal with the ASCII value of a character:

bin2hex() 
chr() 
pack() 
printf() 
sprintf() 
unpack() 

Example:

Display the character code for a newline
<?php echo ord ("\n"); ?> 

Output: 
10 

Get PHP Functions Essential Reference 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.