Character conversion php

Source: Internet
Author: User
Tags binary to decimal decimal to binary
: This article mainly introduces character conversion php. if you are interested in the PHP Tutorial, you can refer to it.

The schematic ASCII code comparison table uses character A as an example to describe the decimal type. for example, 65Hx indicates the hexadecimal type. for example, 41Oct indicates the octal type. for example, 101Char indicates the displayed character, for example, the AASCII code table is divided into two units: 1. the control characters are 0-31 and 1272. the characters 32-126 (1) are 48-characters ~ 57 is 0 to 9 10 Arabic numerals; (2) 65 ~ 90 is 26 uppercase English letters; (3) 97 ~ 26 lower-case English letters (122); (4) other punctuation marks, operator numbers, etc.; 3, PHP character conversion function description for specific description of character conversion functions, refer to [descriptions of PHP functions in decimal, binary, octal, and hexadecimal conversion functions] decimal to binary decbin () function decimal to octal decoct () function decimal to hexadecimal dechex () function binary to hexadecimal to bin2hex () function binary to decimal to bindec () function octal to decimal Dec () function hexadecimal to decimal hexdec () function arbitrary hexadecimal conversion base_convert () function character conversion instance 1, to convert a character to binary, octal, or hexadecimal, you can use the ord () function to convert the character to an ASCII value, and then use the corresponding hexadecimal conversion function to convert it, the following a character is converted to its binary/Octal/hexadecimal format, and the following a character is in decimal format: ord ('A'); // 97 binary is output: decbin (ord ('A'); // enter Output 1100001 octal values: decoct (ord ('A'); // output 141 hexadecimal: dechex (ord ('A ')); // output 61. then, you can check the result of each hexadecimal output corresponding to the above ASCII code comparison table. Example 2: how to convert a binary to hexadecimal or decimal, such as a binary, the following example uses instance 1 to obtain the binary decbin (ord ('A') of the character, and then converts the binary to hexadecimal or decimal hexadecimal: bin2hex (decbin (ord ('A'); // output 31313030303031 binary J: bindec (decbin (ord ('A'); // output 97
1. chr () function this function is used to convert the ASCII code value to a string. The function declaration is as follows: string chr (int ascii); 2.ord() this function is used to convert a string to an ASCII value. The function declaration is as follows: int ord (string str); example: Use the chr () function and ord () function to convert the string and ASCII code. the program code is as follows:
  
** The bin2hex () function converts ASCII character strings to hexadecimal values. Bin2hex (string) parameter description string is required. The string to be converted. The string can be converted back by using the pack () function. The pack () function loads data into a binary string. Pack (format, args +) parameter description format is required. The format used for packaging data. Args + optional. Specify one or more parameters to be packaged. ** $ String = "Hello \ tworld! \ N "; print ($ string. "\ n"); print (bin2hex ($ string ). "\ n "); ========================================================== ==============---- output result: ---- Hello world! ---- 48656c6c6f09776fda-c64210a ================================================== ================ convert "Shanghai" to a hexadecimal value:
  "; Echo pack (" H * ", bin2hex ($ str ))."
";?> ========================================================== ==============---- Output result: ---- 5379616e67686169 ---- Shanghai ============================================== ======================

'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
  • '). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script

    Copyright: all for learning

    The above describes the conversion of characters to php, including the content, hope to be helpful to friends who are interested in the PHP Tutorial.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.