<html>
<head>
<title>Binary</title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<textarea name="text" rows="10" cols="45"></textarea><br>
<input type="submit" name="submit" value="Convert!">
<input type="reset" value="Clear">
</form>
<?php
function binary($str)
{
$text_array = explode("\r\n", chunk_split($str, 1));
for($i = 0; $i < count($text_array) - 1; $i++)
{
$newstring .= substr("0000".base_convert(ord($text_array[$i]), 10, 2), -8);
}
return $newstring;
}
if(isset($_POST['submit']))
{
$text = trim(strip_tags(stripslashes($_POST['text'])));
$text = chunk_split(binary($text), 8, " ");
echo $text;
}
?>
</body>
</html>