How to convert characters to ascii code in php

青灯夜游
Release: 2023-03-17 22:44:01
Original
3746 people have browsed it

In PHP, you can use the ord() function to convert characters into ASCII codes. This function can return the ASCII value of a single character or the first character in a string. The returned ASCII value will be in the form of an integer. Display; conversion syntax "ord(string)", parameter "string" cannot be omitted, it is the string (or single character) from which the ASCII value is to be obtained.

How to convert characters to ascii code in php

The operating environment of this tutorial: windows7 system, PHP8 version, DELL G3 computer

In php, you can use ord() Function to convert characters into ascii code.

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

Syntax:

ord(string)
Copy after login

Parameters:

  • string Required. The string from which to obtain the ASCII value.

Return value:

  • Returns the ASCII value in integer form.

example of the ord() function converting characters to ascii code

<?php
echo ord("a")."<br>";
echo ord("b")."<br>";
echo ord("c")."<br>";
echo ord("d")."<br>";
echo ord("e")."<br>";
echo ord("f")."<br>";
echo ord("g")."<br><br>";

echo ord("A")."<br>";
echo ord("B")."<br>";
echo ord("C")."<br>";
echo ord("D")."<br>";
echo ord("E")."<br>";
echo ord("F")."<br>";
echo ord("G")."<br>";
?>
Copy after login

How to convert characters to ascii code in php

65~ 90 is 26 uppercase English letters, and numbers 97 to 122 are 26 lowercase English letters

Extended knowledge:

ASCII ((American Standard Code for Information Interchange): American Standard Code for Information Interchange) is a computer coding system based on the Latin alphabet, primarily used to display modern English and other Western European languages. It is the most common information exchange standard and is equivalent to the international standard ISO/IEC 646.

ASCII code uses a specified 7-bit or 8-bit binary number combination to represent 128 or 256 possible characters. Standard ASCII code, also called basic ASCII code, uses 7 binary digits (the remaining 1 binary digit is 0) to represent all uppercase and lowercase letters, numbers 0 to 9, punctuation marks, and special controls used in American English. character. Among them:

  • 0~31 and 127 (33 in total) are control characters or special communication characters (the rest are displayable characters), such as control characters: LF (line feed), CR ( Enter), FF (page feed), DEL (delete), BS (backspace), BEL (ring), etc.; communication special characters: SOH (head of text), EOT (end of text), ACK (confirmation), etc.; ASCII values ​​8, 9, 10, and 13 are converted to backspace, tab, line feed, and carriage return characters respectively. They do not have a specific graphic display, but will have different effects on text display depending on the application.

  • 32~126 (95 in total) are characters (32 is a space), of which 48~57 are ten Arabic numerals from 0 to 9.

  • 65~90 are 26 uppercase English letters, 97~122 are 26 lowercase English letters, and the rest are some punctuation marks, arithmetic symbols, etc.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to convert characters to ascii code in php. For more information, please follow other related articles on the PHP Chinese website!

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