How to write binary data to a file?
| From: | David Spector | Date: | Tue, 26 Jul 2016 22:10:07 +0000 |
| Subject: | How to write binary data to a file? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-325662@lists.php.net to get a copy of this message | ||
Hi all,
All I can find in the PHP Manual for writing raw bytes (unsigned integers) to a file is fwrite. But when I use it, it seems to write characters, not raw bytes. For example, the value 1 (0b1) is actually written as 0x31, not 0x01 as desired. Yes, the fopen was done with the "b" mode specified.
It doesn't work this way in C or C++, and the PHP Manual says nothing about this.
Web searches turn up nothing useful on this subject.
I have posted this question on three PHP fora, and have received only unhelpful or irrelevant answers so far.
System: Windows 8.1, PHP 5.5.10