[thelist] Binary file manipulation in PHP

Rick den Haan rick.denhaan at gmail.com
Wed Feb 13 05:02:38 CST 2008


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

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.



More information about the thelist mailing list