Home >Backend Development >PHP Problem >How to convert character a into number in php

How to convert character a into number in php

青灯夜游
青灯夜游Original
2022-04-26 16:09:482626browse

php method to convert the character a into a number: 1. Use the boolval() function, the syntax "boolval('a')" can convert the character a into the number 1; 2. Use the ord() function , the syntax "ord('a')" will return the ASCII value of character a in integer form, that is, convert character a into the number 97.

How to convert character a into number in php

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

php will change the character a Convert to a number

1. Use the boolval() function

boolval() function to convert the variable into a Boolean type, which has only two The values ​​are true (corresponding to the number 1) and false (corresponding to the number 0).

<?php 
header(&#39;content-type:text/html;charset=utf-8&#39;);   
$str = &#39;a&#39;;
echo boolval($str);
?>

How to convert character a into number in php

2. Use the ord() function

## The #ord() function returns the ASCII value of the first character in a string, and can also return the ASCII value of a single character.

The return value is an ASCII value in integer form.

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
$str = &#39;a&#39;;
echo ord($str);
?>

How to convert character a into number in php

Description:

ASCII ((American Standard Code for Information Interchange): American Standard Code for Information Interchange) is a set of computer codes based on the Latin alphabet System 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 was first published as a standard type in 1967, and was last updated in 1986. So far, a total of 128 characters have been defined.

  • 0~31 and 127 (33 in total) are control characters or communication-specific characters (the rest are displayable characters), such as control characters: LF (line feed), CR (carriage return) ), 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 value 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 different applications [1] .

  • 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 character a into number 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