CoderZone.org

Category: >> PHP Code >> Binary to Text / Text to Binary Bookmark and Share

<< lastnext >>

Snippet Name: Binary to Text / Text to Binary

Description: Binary to Text and Text to Binary printer.

Also see:
» Convert Minutes to Days, Hours, an...
» Resize and convert an image to a P...
» Convert text to image in php
» Convert Dollars And Cents Value to...
» LDAP Timestamp Converter
» BR2NL Function - Opposite of NL2BR
» Convert Seconds to Hours:Minutes:S...
» Convert UK Dates To mySQL Format D...
» Convert miles to feet, feet to mil...
» Roman2dec and Dec2Roman
» Convert Minutes to Hours
» Decimal to octal conversion
» Convert minutes to hours #2
» Convert minutes to hours #1
» Convert HTML to plain text
» Convert BBCode Tags
» Secure Auto-Link Maker
» Auto Link Code

Comment: (none)

Author: CoderZone
Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009

<?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) : decbin(ord($txt_str[$i])); 
    } 
    return $bin; 
} 
print text2bin('Isn't this cool?'); 
 
?>
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 4