Home>Article>Backend Development> How to convert between numbers and letters in php

How to convert between numbers and letters in php

青灯夜游
青灯夜游 Original
2022-04-27 17:29:18 3622browse

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.

How to convert between numbers and letters in php

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) . "
"; ?>

How to convert between numbers and letters in php

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")."
"; ?>

How to convert between numbers and letters in php

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!

Statement:
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