If I am exporting a field out of a DB table, How can I convert a string of Binary data into ASCII readable format
Can this be done?
Thanks,
Mike
If I am exporting a field out of a DB table, How can I convert a string of Binary data into ASCII readable format
Can this be done?
Thanks,
Mike
Define "ASCII readable format". Do you just want to arbitrarily read each successive group of 8 bits as the equivalent ASCII character that would correlate to that binary number, or something more meaningful (which would require understanding the format/structure of the particular binary file in question). For the former, you could try this completely untested idea:
$hexString = bin2hex($binaryString);
$ascii = '';
for($ix = 0; $ix <= strlen($hexString) - 1; $ix += 2)
{
$ascii .= chr(hexbin(substr($hexString, $ix, 2)));
}
echo $ascii;
Of course, this could result in some unprintable characters since not all ASCII values in the 0-127 range are printable.
The data coming out of the Oracle table is in RAW format
We are using PHP 5.2 in which The newer version of oci8 was fixed so raw data is treated as binary.
I want to interpret this data as ascii format so I can read the ID number that is coming out
Perhaps [man]unpack[/man] is what you're looking for. Since raw binary doesn't come with any formatting (by definition), it's up to you to supply all the rules that say how each byte is to be interpreted as what.