PHP chr() 函数

PHP chr() 函数

PHP的chr()函数用于从数字生成一个单字节字符串。换句话说,我们可以说它返回指定的ASCII值的字符。

语法

string chr ( int $bytevalue ); 
Parameter Description Required/Optional
ascii An ASCII value Required

示例1

<?php
char =52;
echo "Your character is :".char;
echo "<br>"."By using 'chr()' function your value is: ".chr($char);//  decimal Value
?>

输出:

Your character is :52
By using 'chr()' function your value is: 4

示例2

<?php
char =052;
echo "Your character is :".char;
echo "<br>"."By using 'chr()' function your value is: ".chr($char); // Octal Value
?>

输出:

Your character is :42
By using 'chr()' function your value is: *

示例3

<?php
echo "Your character is :0x52";
echo "<br>"."By using 'chr()' function your value is: ".chr(0x52); // Hex value
?>

输出:

Your character is :0x52
By using 'chr()' function your value is: R

示例4

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

输出:

2 + 2 = 4

在上述程序中,chr(43)的ASCII值是’+’,chr(61)的ASCII值是’=’。

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程