How to convert binary code to text in PHP

1 Answer

0 votes
function bin2text($bin_txt) {  
    $text = ''; 
    $chars = explode("\n", chunk_split(str_replace("\n", '', $bin_txt), 8)); 
    array_pop($chars);
    $len = count($chars);
      
    for ($i = 0; $i < $len; $text .= chr(bindec($chars[$i])), $i++); 
      
    return $text; 
} 
  
echo bin2text("010100000100100001010000001000000101000001110010011011110110011101110010011000010110110101101101011010010110111001100111");

               
               
/*
 
run:
 
PHP Programming
 
*/


answered Aug 27, 2014 by avibootz
edited Apr 14, 2025 by avibootz

Related questions

1 answer 82 views
2 answers 118 views
1 answer 485 views
485 views asked Aug 26, 2014 by avibootz
1 answer 87 views
1 answer 86 views
...