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

How to convert between numbers and letters in php

青灯夜游
Release: 2023-03-15 21:18:01
Original
3752 people have browsed it

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:

<?php
echo chr(65) . "<br>"; 
echo chr(69) . "<br>"; 
echo chr(80) . "<br>";
echo chr(90) . "<br>";
echo chr(97) . "<br>";
echo chr(122) . "<br>";
?>
Copy after login

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.

<?php
echo ord("a")."<br>";
echo ord("f")."<br>";
echo ord("h")."<br>";
echo ord("z")."<br>";
echo ord("A")."<br>";
echo ord("E")."<br>";
echo ord("Q")."<br>";
echo ord("Z")."<br>";
?>
Copy after login

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!

Related labels:
php
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