Page 1 of 1

PHP binary files

Posted: Fri Mar 09, 2007 2:46 am
by mayami
Hi,
I need to send binary data to a server, to which I connect with fsockopen(). I need to send for example 1 byte with value 66 (0x42) and I use fwrite() and pack() functions:

$message_type = pack("v", 66);
fwrite($connection, $message_type, 1);

But I don't know which option of pack() I should use ('v' is 16 bits and I need 8 bits...) I tried several options but it didn't work...Could anyone help me? (It is actually urgent... :( ) Thanks in advance...

Posted: Fri Mar 09, 2007 4:54 am
by Maugrim_The_Reaper
The only 8-bit flag for pack() is a signed or unsigned byte using "c" or "C". Have you tested using c?

Posted: Fri Mar 09, 2007 8:15 am
by stereofrog
hi mayami,

I think you need chr() here