Home > Backend Development > PHP Tutorial > How to score in word? PHP's chr and ord functions implement character addition, subtraction, multiplication and division operations code.

How to score in word? PHP's chr and ord functions implement character addition, subtraction, multiplication and division operations code.

WBOY
Release: 2016-07-29 08:47:27
Original
1921 people have browsed it

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);
echo $str1; //The return value is X
$str2=chr(ord(X)+1); //
echo $ str2; //The return value is Y
echo "t";
$str3=ord('S');
echo $str3; //The return value is 83
?>


Run result: X Y 83 The above introduces how to score in word. PHP's chr and ord functions realize the code for character addition, subtraction, multiplication and division. It includes the content of how to score in word. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template