PHP implementation of binary and text conversion methods _php skills

Source: Internet
Author: User
Tags ord

This article describes the PHP implementation of binary and text mutual conversion method. Share to everyone for your reference. Specifically as follows:

This code contains two functions, Bin2text, binary converted to text, Text2bin, text converted to binary

<?php
function 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 (Decbin (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 to Are you gentlements? ');
? >

I hope this article will help you with your PHP program design.

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.