PHP Array to binary file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
samestreet
Forum Newbie
Posts: 1
Joined: Thu Feb 20, 2014 10:41 am

PHP Array to binary file

Post by samestreet »

Hello folks!

Well, I have an unusual question about binary files. I want to store a PHP array in a binary file, but, one of the array elements will be the content of a zip file. I'll explain:

$array = Array('some_info' => 'the_info', 'another_info' => 'the_another_info', 'file_content' => $loaded_zip_file);

I want to write a new binary file with the array information and, once I can open this binary file, I will read the 'file_content' element and create a temporary file. Basically, I want to create a new kind of file and (I think) it must have a binary header, right?

A better explain: I need a zip file and some information within a file, like a packed file or a datafile (Allegro users will understand).

Thanks in advance my friends!
Best regards
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: PHP Array to binary file

Post by Weirdan »

Does it have to be binary? Do you have any compatibility constraints, like having a requirement to generate files compatible with some existing application?

Generally, php deals with binary data using pack()/unpack() functions.

Alternatively, you could just serialize() the array and store result in a file.
Post Reply