reading binary data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Roger  Lord

    reading binary data


    I need to use php to read binary files that begin something like this:

    00000000: 06 00 00 00 43 5f 54 4b 84 05 00 00 2c 00 00 00
    00000010: 73 65 63 20 18 00 00 00 02 00 00 00 00 00 c0 40
    00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 c1

    The first 4 bytes are a long number. I can't figure out how to fread
    longs into an integer in php. Basically I need a function like:

    $n = read_int($fp, $offset);

    And the same thing for floats, doubles, shorts, unsigned shorts, etc.

    How do you do this in php? I know that the file need to be opened in
    binary mode, but fread just returns a string.


  • Daniel Tryba

    #2
    Re: reading binary data

    Roger Lord <rlord17889@yah oo.com> wrote:[color=blue]
    > $n = read_int($fp, $offset);
    >
    > And the same thing for floats, doubles, shorts, unsigned shorts, etc.
    >
    > How do you do this in php? I know that the file need to be opened in
    > binary mode, but fread just returns a string.[/color]

    Seems you are looking for pack()/unpack().

    --

    Daniel Tryba

    Comment

    Working...