Forum Moderators: coopster

Message Too Old, No Replies

Reading From a Binary File

How To

         

Zorth

6:50 pm on Apr 28, 2004 (gmt 0)

10+ Year Member



Hey,

I have a file with information formatted in Binary, which was saved from a C++ program. It's in a structure with different data types: Strings, integers, more structures...

I use fread() to read each structure, and it returns the binary data, but I can't seem to get it to understand what part of it I want to use.

Any suggestions?

hakre

12:08 am on Apr 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi zorth,

this is farly a detailed question. first of all you need to know how each part of c++ variable type is saved. i don't know a built in function in php that does a parsing for you, so you need to do it for yourself.

this is quite like building a filefilter for jpeg files or similar. you need to parse the wohle file for datatypes and extract them each.

--hakre

Zorth

4:56 pm on Apr 29, 2004 (gmt 0)

10+ Year Member



Let's say I have the memory on an object named $data, how would I go about parsing something simple which contains:

A string of 8 bytes
2 integers of 4 bytes each

?

Timotheos

7:05 pm on Apr 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm thinking that unpack [php.net] might be what you're after. Have a look at the user notes.