Advertisement
toribio

toribio

Mar 2nd, 2009
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. <form id="area" name="area" method="post" action="bin2string.php">
  2.     <textarea name="text" cols="100" rows="5" id="text" tabindex="0"><?= $_POST['text'] ?></textarea><br />
  3.     <input type="submit" name="bin2string" id="bin2string" value="bin > string" tabindex="1" />
  4. </form>
  5.  
  6. <?php
  7.  
  8. function bin2string($bin_string)
  9. {
  10.     $revertido = strrev($bin_string);
  11.     for($i = 0; $i < strlen($revertido); $i += 8)
  12.     {
  13.         $resultado = chr(bindec(strrev(substr($revertido, $i, 8)))).$resultado;
  14.     }
  15.     return $resultado;
  16. }
  17.  
  18. if($_POST['bin2string'])
  19. {
  20.     if(strlen($_POST['text']))
  21.     {
  22.         $string = str_replace("\r", "", trim(str_replace("\n", "", trim($_POST['text']))));
  23.         echo "Resultado: <br />".bin2string($string);
  24.     } else {
  25.         echo "Erro: insira um código binário!";
  26.     }
  27. }
  28.  
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement