How to convert character a into number in php

青灯夜游
Release: 2023-03-15 20:22:02
Original
2543 people have browsed it

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);
?>
Copy after login

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);
?>
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!