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.