Php's chr and ord functions implement character addition, subtraction, multiplication, division operations to implement code

Source: Internet
Author: User

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 a computer. Its value ranges from 0 to 255, including punctuation, letters, numbers, and Chinese characters. During programming, the specified characters are often converted into ASCII codes for comparison.

The following is a function provided by PHP to convert ASCII codes and characters.
1. chr () function
This function is used to convert an ASCII value to a string. The function declaration is as follows:
String chr (int ascii );
2. ord () function
This function is used to convert a string to an ASCII value. The function declaration is as follows:
Int ord (string str );
Example:
Use the chr () and ord () functions to convert strings and ASCII codes. The program code is as follows:Copy codeThe Code is as follows: <? Php
$ 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; // return value: 83
?>

Running result: x y 83

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.