views:

177

answers:

2

I've worked with reading and writing text files with PHP. Now, I'd like to read and write binary files. I've not found any useful resources/tutorials for doing this with PHP5. Is it possible? How?

Specifically, I'll be searching for specific 2-byte patterns.

If it matters, I'm on a Mac (OS X 10.4 Tiger).

A: 

You can use fopen("filename.ext", "rb") under Windows. Which OS are you interested in?

Anyway you can find information about binary files in PHP5 documentation for function fopen.

Jiri
+3  A: 

You can fopen() your binary with 'b' (for binary) attached to the mode parameter. Reading from the stream is done by fread(). PHP offers the common binary operators for manipulating your data.

Till Theis