Home >Backend Development >PHP Problem >How to convert php ascii code

How to convert php ascii code

藏色散人
藏色散人Original
2020-08-27 09:33:095348browse

php ASCII code conversion method: 1. Use the chr function to return characters from the specified ASCII value; 2. Use the ord function to return the ASCII value of the first character in the string.

How to convert php ascii code

Recommended: "PHP Video Tutorial"

PHP Conversion between ASCII codes and characters

ASCII code conversion character:

<?php
$i = 65;
$ch = chr($i);
var_dump($ch);
?>
string &#39;A&#39; (length=1)

chr() function returns characters from the specified ASCII value.

ASCII values ​​can be specified as decimal, octal, or hexadecimal values. Octal values ​​are defined with leading 0, and hexadecimal values ​​are defined with leading 0x.

Character conversion to ASCII code:

<?php
$ch = &#39;A&#39;;
$i = ord($ch);
var_dump($i);
?>
int 65

ord() function returns the ASCII value of the first character in the string.

The above is the detailed content of How to convert php ascii code. 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