Re: Binary to ASCII
| From: | Aidan Lister | Date: | Tue, 11 May 2004 12:42:25 +0000 |
| Subject: | Re: Binary to ASCII | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-185903@lists.php.net to get a copy of this message | ||
Handy function for this sort of stuff:
http://ircphp.com/users/imho/?file=function.hexview.php
"René fournier" <m5@renefournier.com> wrote in message
news:44B05AA1-A2D5-11D8-91FF-0003931DAC94@renefournier.com...
> When reading from a Socket Server, my Socket Client retrieves data that
> includes ASCII and binary data:
>
> while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) {
> $data .= $buf;
> if(preg_match("/ENX/", $data)) break;
> }
> echo "RESPONSE: ".$data."\n";
>
> The output looks like:
> RESPONSE: STX&The system is up and running.ENX
>
> Between the "STX" and "The system is up..." are 8 bytes of binary data
> (which this case appear as an ampersand), which I want to extract from
> $data, split into two 4 byte variables, and convert back into integers.
> I suspect that I need unpack() at some point, but any ideas how to
> extract and split the binary data from this string? (Sometimes, the
> binary data is not visible, but it's still there.)
>
> ...Rene
>
> PS. Thanks guys for the earlier advice with pack()--which worked.