Conversion of characters to PHP

Source: Internet
Author: User
Tags control characters decimal to binary ord

Graphic ASCII code comparison chart, with character A as an example dec denotes decimal, as $HX denotes hexadecimal, such as AThe OCT represents octal, as in101Char represents a display character, such as a AASCII code comparison chart divided into two cells1, control characters0- toAnd1272, the characters can be displayed +-126(1) -~ $For0To910 x Arabic numerals; (2) $~ -For -uppercase English letters; (3) the~122Number is -A lowercase English letter; (4Other punctuation marks, arithmetic symbols, etc. three, the PHP character conversion function Description of the specific character conversion function description please refer to [PHP function chapter detailed decimal, binary, octal and 16 conversion function description] decimal to binary decbin () function decimal to octal decoct () function decimal to hexadecimal dechex () function binary turn 16 Bin2Hex () function binary turn 10 into Bindec () function octal to decimal octdec () function hexadecimal to decimal hexdec () function arbitrary binary conversion Base_convert ( ) function to convert instance instance one, how 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 conversion function to convert, a this character is converted to the second binary/eight binary/16 binary, Decimal of the A character as follows: Ord (' A ');//OutputBinary: Decbin (ORD (' A '));//Output 1100001Octal: Decoct (Ord (' A '));//Output 141Hex: Dechex (Ord (' A '));//OutputYou can then check the results of each input output corresponding to the above ASCII code comparison chart. Example two, how to convert a binary to 16 binary or decimal, such as the binary of a, as follows using the method of instance one to get the A-character binary Decbin (ord (' A '); then convert the binary to 16 hexadecimal or decimal hex: Bin2Hex (Decbin (ORD) (' A ')));//Output 31313030303031Binary J:bindec (Decbin (ORD) (' A ')));//Output
1.chr()函数该函数用于将ASCII码值转化为字符串。其函数声明如下:string chr (int ascii);2.ord()函数该函数用于将字符串转化为ASCII码值。其函数声明如下:int ord(string str);示例:使用chr()函数和ord()函数进行字符串与ASCII码之间的转换,程序代码如下:
   
    $str1=chr(88);echo$str1;               //返回值为Xecho"\t";$str2=ord('S');echo$str2;               //返回值为83?>
The **bin2hex () function converts a string of ASCII characters to a hexadecimal value. The Bin2Hex (String) parameter describes the string required. The string to convert. Strings can be converted back by using the pack () function. The pack () function loads the data into a binary string. The pack (format,args+) parameter describes the format required.    Specifies the format to use when wrapping the data. Args+ is optional. Specifies one or more parameters that are packaged. **$string="hello\tworld!\n";Print($string."\ n");Print(Bin2Hex ($string)."\ n"); ====================================================----OUTPUT Result:--------Hello World!--------48656c6c6f09776f726c64210a==================================================== put"Shanghai"Convert to hexadecimal value:
 
    $str = "Shanghai"; echo bin2hex ($str). "
"; echo Pack ("h*", Bin2Hex ($str)). "
"; Results of the ?>====================================================----output:---- 5368616e67686169- ---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); }); });

    Copyright notice: All for learning

    The above describes the character conversion PHP, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • 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.