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值是’=’。