[thelist] Binary file manipulation in PHP

Rick den Haan rick.denhaan at gmail.com
Thu Feb 14 08:28:28 CST 2008


Luther, Ron wrote:
> Sorry, I thought your original note said that you had a 'VERY' detailed
> file spec.  I assumed that you meant that the spec already told you which
> fields were 'zone packed decimal' or 'multi-punch column binary' - which,
> if this data is really *that* old are format types you could easily run
into.

Actually, I said "reasonably detailed," by which I meant that I at least
know what piece of information is in the file, in what order, and how many
bytes it takes up. Although there are a few items that are terminated by
NUL-bits, but I think a simple loop will take care of that.

> If you are going to have to _guess_ at each of the field types then I
think
> you are in for some very long days.

Well, I'll have to guess insofar as I can pretty much assume numeric values
are not stored as strings, but as signed/unsigned integers or floats.

> Especially if you don't know the underlying system the data came from.

I *think* the original application that generated the files ran on a variant
of UNIX, and was compiled in C. I'm not sure, though, and I don't know if
that helps at all, but i fit *was* C, PHP's unpack() should work.

Thanks for the help so far, I'll see whether I can extract the actual
information from the files over the weekend. I have already succesfully
retrieved the file header information (well, at least it was information
that makes sense with regards to the information that is supposed to be in
the file), so I think I'm on the right track here.

Cheers,

Rick.




More information about the thelist mailing list