0

我正在尝试将一串位保存到二进制文件中。

这是我的字符串

01001001010011100101000001010101010101000011000100000000000000000100100101001110010100000101010101010100001100100000000000000000010010010100111001010000010101010101010000110011000000000000000001001001010011100101000001010101010101000011010000000000000000000100100101001110010100000101010101010100001101010000000000000000010010010100111001010000010101010101010000110110000000000000000001001001010011100101000001010101010101000011011100000000000000000100100101001110010100000101010101010100001110000000000000000000010100100100010101001100010000010101100100110001000000000000000001010010010001010100110001000001010110010011001000000000000000000101001001000101010011000100000101011001001100110000000000000000010100100100010101001100010000010101100100110100000000000000000001010010010001010100110001000001010110010011010100000000000000000101001001000101010011000100000101011001001101100000000000000000010100100100010101001100010000010101100100110111000000000000000001010010010001010100110001000001010110010011100000000000000000000011000000000000001100000000000000110000000000000011000000000000001100000000000000110000000000000011000000000000001100000000000000110001001100000011000100110000001100010011000000110001001100000011000100110000001100010011000000110001001100000011000100110000001011010011001100101101001100110010110100110011001011010011001100101101001100110010110100110011001011010011001100101101001100110011001100110010001100110011001000110011001100100011001100110010001100110011001000110011001100100011001100110010001100110011001000110000000000000011000000000000001100000000000000110000000000000011000000000000001100000000000000110000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000110000

这是我用来编写它的代码。

$fp = fopen('io2454929593', 'wb');
fwrite($fp, pack('C*', $bytes));
fclose($fp);

我得到的只是一个 1 字节长的文件,但它应该更长。我究竟做错了什么?

4

1 回答 1

0

你可以试试这个:

$s = '0100100101001110'; // your binary string

$chars = array_map('bindec', str_split($s, 8));
array_unshift($chars, 'C*');
echo call_user_func_array('pack', $chars);

免责声明:这段代码只是说明了pack应该如何调用;它不应该用于大字符串。

于 2012-05-02T07:51:25.653 回答