Home > Article > Backend Development > PHP's chr and ord functions implement character addition, subtraction, multiplication and division operations code_PHP tutorial
The chr function is used to convert ASCII codes into characters
ord function is used to convert characters into ASCII codes
ASCII code is the encoding of characters that the computer can display. Its value range is 0-255. These include punctuation, letters, numbers, Chinese characters, etc. During the programming process, specified characters are often converted into ASCII codes for comparison.
The following is the function provided by PHP to convert ASCII codes and characters.
1. chr() function
This function is used to convert ASCII code value into a string. Its function declaration is as follows:
string chr (int ascii);
2. ord() function
This function is used to convert a string into an ASCII code value. The function declaration is as follows:
int ord(string str);
Example:
Use the chr() function and ord() function to convert strings and ASCII codes. The program code is as follows:
www.bkjia.com