PHP ord function
PHP ord function can be used to return a string of ASCII code value, for example, the letters A ASCII code 65, the @ symbol mice ASCII code is 64, word symbols # ASCII code is 35, these special characters to obtain The ASCII code can be converted through PHP's built-in ord function. The corresponding function of the ord function is the chr function . These two functions are common functions that PHP uses to convert string characters and ASCII codes. The difference between the two as follows:
- ord function: convert string to ASCII code
- chr function : convert ASCII code to string
PHP ord function application example 1: Convert a string to ASCII code
echo'Convert character # into ASCII code:'.ord('#').'<br>';
echo'Convert character% into ASCII code:'.ord('%').'<br >';
echo'Convert character @ into ASCII code:'.ord('@').'<br>';
echo'Convert character A into ASCII code:'.ord('A').'<br >';
echo'Convert the character a to ASCII code:'.ord('a').'<br>';
?>
Convert character% to ASCII code: 37
Convert character @ to ASCII code: 64
Convert character A to ASCII code: 65
Convert character a to ASCII code: 97
➤The " ASCII Code Table " on this site and the ASCII Code query tables of two external websites: ASCII-Wikipedia | Ascii Table
PHP ord function application example 2: Relative conversion with chr function
echo'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'; //Web page encoding declaration
$str1 = '66';
echo'from ASCII code 66 The result of converting back to the English letter B:'.chr($str1).'<br>';
$str2 ='B';
echo'The result of converting the English letter B to ASCII code:'.ord($str2). '<br>';
echo'First use chr to convert the ASCII code into a string, and then use ord to convert back to the ASCII code result:'.ord(chr($str1));
?>
converting English letter B to ASCII code: 66
First use chr to convert the ASCII code to a string, and then use ord to convert back to ASCII code: 66
Post a Comment
0 Comments