[thelist] Binary file manipulation in PHP

David Menzel DavidM at circlebroach.net
Wed Feb 13 09:37:51 CST 2008

While I havnt done to much with binary files in php, i believe you need 
the file_get_contents function.

Also, you could try setting the binary flag on fread if you havnt already.

Good luck

Rick den Haan wrote:
> All,
> I am a complete novice when it comes to binary operations, and Google is not
> helping because I don't know the correct keywords to get what I need to
> know.
> Here's the situation. A long, long time ago, some developer at my company
> invented a custom file format. The software to read these files no longer
> exists, but I need to read out a couple of these files anyway. Fortunately,
> there is a reasonably detailed file format description available (the
> developer himself passed away a few years ago).
> Simply opening the files in Notepad gives a load of gibberish, so I'm trying
> to work off of the specs, that say about the beginning of the file:
> offset 0x00: 2 bytes, version
> offset 0x02: 8 bytes, filetype constant (there are several types of files,
> the documentation branches off to handle each file type)
> offset 0x0A: 2 bytes, count of items
> ...etc detailing the whole file
> I can open the file using fopen(), and read out its contents using fread()
> and fseek(), but how do I convert something that Notepad thinks looks like "
> ¬" into a version number? PHP is the only "language" I feel comfortable
> enough in to try this, and I'm sure it's possible somehow.
> If anyone can point me to some resources on how to handle this, I'd
> appreciate it.
> TIA,
> Rick.

More information about the thelist mailing list