<?php
//giberish.php ver 1.0
//written in php5.2 by Tom Veile 1/26/2011
//Read a file of binary and save to a text file.
//using procedural programming techniques in PHP
//for the Not just tiny-C Programming group
//Facebook
//
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Gibberish to Text</title>
<style type="text/css">
        body {
                margin: 0;
                padding: 0;
                font-family: Verdana, sans-serif;
                font-size: small;
                background: #fff;
        }
        h1, h2, h3 {
                display: block;
                text-align: center;
        }

        p {
                display: block;
                text-align: center;
                font-weight: bold;
        }

        b {     margin: 1.5em;
        }
</style>
</head>
<body><table align=center width=89%><tr><td>
<h1>Gibberish to Text</h1>
<?php
echo "<b>Reading file 'binary.bin'</b>";
$handle = fopen("./binary.bin", "r");
$contents = fread($handle,8192);
fclose($handle);
echo "<br />";
echo "<p>".$contents."</p>\n";
echo "<b>Deciphering binary gibberish</b>";
$nospaces = str_replace(" ", "", $contents);
$message = $binary = '';
for ($i = 0, $len = strlen($nospaces)-1; $i < $len; $i=$i+8)
{$message .= chr(bindec(substr($nospaces,$i,8)));}
echo "<br /><br />";
echo "<p>".$message."</p>\n";
echo "<br /><br />";
echo "<b>writing to file 'talk.txt'</b>"; 
$handle = fopen("./talk.txt", "w");
$fp=fwrite($handle, $message);
fclose($handle);
echo "<br />";
echo "<h2>DONE</h2>";
?>
</td></tr></table>
</body>
</html>