Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Building a binary 'string' with PHP
December 6, 2006, 12:26 am
rate this thread
array of integers into a binary 'string'.
Let's say I have this:
int = 0x1234
int = 0x5678
int = 0x9abc
int = 0xdef0
I have to produce a string containing
0x 12 34 56 78 9a bc de f0
and send it off. The string contains the ints packed together in
big-endian order: HI LO HI LO HI LO.
In C, I can do this pretty easily, but I am not familiar enough with
PHP's data handling. I don't even know where to begin.
I know PHP can do it, since it handles images but how do you build
something like this from scratch? How can you build a string byte by byte?