Home  >  Article  >  Backend Development  >  How to use php chr function?

How to use php chr function?

藏色散人
藏色散人Original
2019-05-30 10:06:412774browse

php chr function is used to return characters from the specified ASCII value. The syntax is chr(ascii), the parameter ascii is required and refers to the ASCII value. ASCII values ​​can be specified as decimal, octal, or hexadecimal values.

How to use php chr function?

#How to use php chr function?

Definition and Usage

The chr() function returns the character 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.

Syntax

chr(ascii)

Parameters

ascii required. ASCII value.

Return value: Returns the specified character.

PHP Version: 4

Example 1

Use the octal value 046 to add the ASCII character: &.

<?php
$str = chr(046);
echo("You $str me forever!");
?>

Output:

You & me forever!

Example 2

Use decimal values ​​43 and 61 to add ASCII characters: and =.

<?php
$str = chr(43);
$str2 = chr(61);
echo("2 $str 2 $str2 4");
?>

Output:

2 + 2 = 4

Example 3

Returning characters from different ASCII values:

<?php
echo chr(61) . "<br>"; // 十进制
echo chr(061) . "<br>"; // 八进制值
echo chr(0x61) . "<br>"; // 十六进制值
?>

Output:

=
1
a

The above is the detailed content of How to use php chr function?. 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