The chr function is used to convert ASCII codes into characters. The ord function is used to convert characters into ASCII codes. ASCII code is the encoding of characters that can be displayed by the computer. Its value range is 0-255, including punctuation, letters, and 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 values into strings. Its function is declared 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 chr() function and ord() function to convert between string and ASCII code. The program code is as follows:
Copy code The code is as follows:
$str1=chr(88);