PHP chr function



 The function of the PHP chr function can be used to convert a specified ASCII code back to a character. The ASCII that the PHP chr function can convert includes octal , decimal, and hexadecimal. The converted characters may be graphics, symbols, or English letters, for example , the octet ASCII code of the @ symbol is 100. As long as you put 0100 into the parameter bit system of the chr function, you can convert the @ symbol. When ASCII was popular in the early years , the use of PHP chr function was very common, but now it is common Use Unicode instead of the traditional ASCII Code.


Basic syntax of PHP chr function
chr (ASCII);
The PHP chr function has only one parameter, ASCII, which is required. The supported octal, decimal and hexadecimal systems are supported. Except that the decimal system can be used directly, 0 must be added before the ASCII of the octal system. Judgment, the hexadecimal system needs to add 0x to make the judgment. Below we use different carry system examples to convert the chr function.

PHP chr function application example
<?php
echo chr(64).'<br>'; //output @
echo chr(0100).'<br>'; //output @
echo chr(0x40).'<br>'; //output @
echo chr(66).'<br>'; //output B
echo chr(0102).'<br>'; //output B
echo chr(0x42).'<br>'; //output B
? >
Output result
@
@
@
B
B
B
The example is divided into two output results. Three different carry systems, such as decimal system, octal system, and hexadecimal system, are used to convert the chr function. Take the @ symbol as an example. The ASCII code of the decimal system @ symbol is 64 , 8 binary system @ sign ASCII code is 100,16 binary system @ symbol ASCII code is 40, when we want to convert must be 8 binary system ASCII plus 0 foregoing codes become 0100, in hexadecimal Add 0x in front of the ASCII to become 0x40, and then enter the chr conversion to get the result.

➤The ASCII Code query table of the two external websites of the " ASCII Code Table " on this site ASCII-Wikipedia | Ascii Table
➤ The PHP chr function and the ord function are complementary, please refer to: PHP ord function .

Post a Comment

0 Comments