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

How to convert letters to decimal numbers in php

青灯夜游
青灯夜游Original
2022-01-24 19:03:413031browse

In PHP, you can use the ord() function to convert letters into decimal numbers. This function can return the ASCII value of a single character, or the ASCII value of the first character in a string. The syntax is " ord("specified letter")".

How to convert letters to decimal numbers in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In php, you can use ord () function to convert letters into decimal numbers.

Example:

<?php
echo ord("a")."<br>";
echo ord("b")."<br>";
echo ord("c")."<br>";
echo ord("d")."<br>";
echo ord("A")."<br>";
echo ord("B")."<br>";
echo ord("C")."<br>";
echo ord("D")."<br>";
?>

How to convert letters to decimal numbers in php

Explanation:

ord() function can return The ASCII value of a single character, or the ASCII value of the first character in a string.

Syntax:

ord(string)
Parameters Description
string Required. The string from which to obtain the ASCII value.

Return value: Returns the ASCII value in integer form.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to convert letters to decimal numbers 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