stalepretzel
stalepretzel

Reputation: 15913

How can I read/write from/to a file, byte by byte, with PHP5?

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).

Upvotes: 2

Views: 2518

Answers (2)

Till Theis
Till Theis

Reputation: 1238

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.

Upvotes: 4

Jiri
Jiri

Reputation: 16625

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.

Upvotes: 0

Related Questions