Advertisement
fruffl

Binary2Chars

Apr 25th, 2012
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1.                 public function bin2Char($value)
  2.                 {
  3.                         $strlen = mb_strlen($value, DataType::ENCODING);
  4.                        
  5.                         $result = [];
  6.                        
  7.                         if($strlen % 8 !== 0)
  8.                             return FALSE;
  9.                        
  10.                         while($strlen > 0)
  11.                         {
  12.                                 $result[]       = mb_substr($value, 0, 8,       DataType::ENCODING);
  13.                                 $value          = mb_substr($value, 8, $strlen, DataType::ENCODING);
  14.                                 $strlen         = mb_strlen($value);
  15.                         }
  16.                        
  17.             $words = [];
  18.             foreach($result as $binChar)
  19.                 $words[] = chr(bindec($binChar));
  20.  
  21.                         return implode('', $words);
  22.                 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement