Home>Article>Backend Development> How to convert between numbers and letters in php
Methods for converting numbers and letters to each other: 1. Use the chr() function to convert specified numbers into letters. The syntax "chr (number)" will convert the ASCII value in the form of an integer to the specified letter. ; 2. Use the ord() function to convert specified letters into numbers. The syntax "ord (letter)" will return an ASCII value in the form of an integer.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php can realize digital through the following two functions and mutual conversion between letters:
chr() function
ord() function
1. Use the chr() function to convert specified numbers into letters
chr() function returns characters from the specified ASCII value.
ASCII is a computer encoding system based on the Latin alphabet, using specified 7-bit or 8-bit binary number combinations to represent 128 or 256 possible characters. Among them:
65~90 means: 26 uppercase English letters
97~122 means: 26 lowercase English letters
Example:
"; echo chr(69) . "
"; echo chr(80) . "
"; echo chr(90) . "
"; echo chr(97) . "
"; echo chr(122) . "
"; ?>
2. Use the ord() function to convert the specified letters into numbers
The ord() function returns the ASCII value of the specified character. Returns the ASCII value as an integer.
"; echo ord("f")."
"; echo ord("h")."
"; echo ord("z")."
"; echo ord("A")."
"; echo ord("E")."
"; echo ord("Q")."
"; echo ord("Z")."
"; ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert between numbers and letters in php. For more information, please follow other related articles on the PHP Chinese website!