Re: How to write binary data to a file?
| From: | David Spector | Date: | Tue, 26 Jul 2016 23:47:12 +0000 |
| Subject: | Re: How to write binary data to a file? | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-325666@lists.php.net to get a copy of this message | ||
Shiplu,
fprintf($Res, "%c", $IDByte);
worked. It actually wrote a byte containing 0b1. Whew.
Clearly, the problem was with fwrite converting its value to a character. It shouldn't do this, IMO, since fwrite is documented as working both for string and binary arguments (depending on the 'b' mode of fopen).
Anyway, thank you for the solution, even though PHP is acting very non-intuitively here.
I consider this question closed now: fwrite can only write strings. Thanks to everyone for the responses.
David