Home > Backend Development > PHP Tutorial > PHP's chr and ord functions implement character addition, subtraction, multiplication and division operations code_PHP tutorial

PHP's chr and ord functions implement character addition, subtraction, multiplication and division operations code_PHP tutorial

WBOY
Release: 2016-07-21 15:22:20
Original
1251 people have browsed it

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:

Copy code The code is as follows:

$str1=chr(88);
echo $str1; //The return value is >$str3=ord('S');
echo $str3; //The return value is 83
?>


Run result: X Y 83


http://www.bkjia.com/PHPjc/324706.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/324706.htmlTechArticlechr function is used to convert ASCII code to characters ord function is used to convert characters to ASCII code ASCII code is a computer The encoding of characters that can be displayed, its value range is 0-255, including punctuation,...
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