Trying to do something like this, but haven't been able to figure out...
Any help is greatly appreciated.
ascii value to 8-bit binary value
Thats wicked....if you find out how it was done please post it onto the forum
Ah... thank a lot
Whipped these up a while back. You could probably edit them to fit your requirements.
function text2bin($string) {
for($i=0; $i<strlen($string); $i++) {
if( ($c = ord($string{$i})) != 0) $bin .= decbin($c);
if( $i != (strlen($string) -1) ) $bin .= ":";
}
return $bin;
}
function bin2text($binstr) {
$bin = explode(":",$binstr);
for($i=0; $i<count($bin); $i++)
$txt .= chr(bindec($bin[$i]));
return $txt;
}
heres a new script I just wrote up with the help of above
<?
function txt2bin($str) {
$text_array = explode("\r\n", chunk_split($str, 1));
for ($n = 0; $n < count($text_array) - 1; $n++) {
$newstring = substr("0000".base_convert(ord($text_array[$n]), 10, 2), -8);
echo $newstring."\n";
}
}
function bin2txt($str) {
$text_array = explode("\r\n", chunk_split($str, 8));
for ($n = 0; $n < count($text_array) - 1; $n++) {
$newstring = stripslashes(chr(base_convert($text_array[$n], 2, 10)));
echo $newstring;
}
}
$var = "01101000 01100101 01101100 01101100 01101111";
$filter = eregi_replace(" ", "", $var);
bin2txt($filter);
echo "<br>";
$var = "hello";
txt2bin($var);
?>
Thank you all for your replies