[PLUG] Reading/Writing Binary Files with PHP
Bill Thoen
bthoen at gisnet.com
Tue Aug 31 11:18:02 UTC 2004
Is it possible to write binary data to a file with PHP? When I try this:
$data = 128;
$fp = fopen ("test.bin", "w+b");
fwrite ($fp, (int) $data);
fclose ($fp);
I get a file called test.bin that has the string "128" in it, and not the
binary 0x0080 value.
I didn't find any useful answer on Google; just people asking a similar
question and others answering not with an answer but with another
question, "Why do you want to do that?"
So before anyone asks, I want to do this because I want to create a
look-up index into another file that contains lines of text. If I want to
access, say, the 25th line, I want to go into the index file, jump to the
25th long int in the index, and retrieve the offset to the 25th line in
the text file.
- Bill
More information about the PLUG
mailing list