Binary to ASCII

From: Date: Mon, 10 May 2004 22:56:27 +0000
Subject: Binary to ASCII
Groups: php.general 
Request: Send a blank email to php-general+get-185871@lists.php.net to get a copy of this message
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.

« previous php.general (#185871) next »