PHP implementation of binary and text conversion method, _php tutorial

Source: Internet
Author: User

PHP implements binary and text to convert each other method,


In this paper, we describe the method of translating PHP into binary and text. Share to everyone for your reference. Specific as follows:

This code contains two functions, bin2text, binary conversion to text, Text2bin, text into binary

<?phpfunction Bin2text ($bin _str) {$text _str = '; $chars = explode ("\ n", Chunk_split (Str_replace ("\ n", "", $bin _str), 8)); $_i = count ($chars); for ($i = 0; $i < $_i; $text _str. = Chr (Bindec ($chars [$i])), $i); return $text _str;} function Text2bin ($txt _str) {$len = strlen ($txt _str); $bin = "; for ($i = 0; $i < $len; $i) {  $bin. = strlen (DECBI N (Ord ($txt _str[$i])) <8?str_pad (Decbin (Ord ($txt _str[$i)), 8,0,str_pad_left):d Ecbin (Ord ($txt _str[$i])); } return $bin;} Print Text2bin (' How is you gentlements? ');? >

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/986075.html www.bkjia.com true http://www.bkjia.com/PHPjc/986075.html techarticle PHP Implementation of binary and text to convert the method, this article describes the implementation of PHP binary and text conversion method. Share to everyone for your reference. As follows: This period of ...

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