PHP binary files

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
mayami
Forum Newbie
Posts: 1
Joined: Fri Mar 09, 2007 2:33 am

PHP binary files

Post 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...
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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?
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

hi mayami,

I think you need chr() here
Post Reply