The CHR function is used to convert an ASCII code to a character
The ORD function is used to convert characters to ASCII code
ASCII code is the computer can display the character encoding, its value range is 0-255, including punctuation, letters, numbers, Chinese characters and so on. In the programming process, the specified characters are often converted to ASCII code for comparison.
The following is a function that PHP provides 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 to an ASCII code value. Its function is declared as follows:
int ord (string str);
Example:
Use the Chr () function and the Ord () function to perform the conversion between the string and the ASCII code as follows:
Copy the Code code as follows:
$str 1=CHR (88);
echo $str 1; The return value is X
$str 2=CHR (Ord (X) +1); //
echo $str 2; The return value is Y
echo "\ T";
$str 3=ord (' S ');
echo $str 3; The return value is 83
?>
Run Result: X Y 83
The above describes how Word scores PHP's CHR and Ord function to implement the character subtraction operation implementation code, including the word how to score content, I hope that the PHP tutorial interested in a friend helpful.