reading binary data

From: Roger Lord (rlord17889_at_yahoo.com)
Date: 08/31/04


Date: Tue, 31 Aug 2004 08:46:22 -0400


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.



Relevant Pages

  • Re: [PHP] Find file version
    ... I found microsoft's "Filever" program, but I can't get exec working properly. ... and then uploads to file hippo to compare ... I know binary files have version ... but can't find anything for php to read this. ...
    (php.general)
  • Re: Securely serving files
    ... He didn't say the were binary files. ... readfile() doesn't execute the file as PHP. ... It's dangerous and doesn't solve the problem in the original post (which ...
    (comp.lang.php)
  • Re: HTTP POST problem
    ... client application is lightweight. ... Is there any way I can be able to access http raw data or correct ... binary files. ... PHP Classes - Free ready to use OOP components written in PHP ...
    (comp.lang.php)
  • Re: Securely serving files
    ... He didn't say the were binary files. ... readfile() doesn't execute the file as PHP. ...
    (comp.lang.php)
  • Copy webpage, protected by session
    ... I want to copy a page from the internet with fopen and fread. ... website see php as a logged in user, and then let the same script php ... with netscape, logged in, and copy all the vars the website had stored ...
    (alt.php)