Reputation: 2549
I have a string containing something like "01001010" and I want to write it into a file using binary. In other words, what's inside that file is not the chars 0/1, but in binary format. How can I make that?
Upvotes: 2
Views: 213
Reputation: 55271
So you mean you want to convert a string of 0s and 1s (eg $bitString = '01010101...';
) into binary data (0x55...), and then write that to a file, you need to do this in two steps.
First, convert your string of zeros and ones into binary - see Converting string of 1s and 0s into binary value, then compress afterwards ,PHP
Note that strings in PHP can store binary data.
Then just write the output to a file, eg using file_put_contents()
.
Upvotes: 2