0

PHP socket_write takes a string and length as parameters. I am not sure how can I convert a 4-byte array (xmlHeader) to a string, as some of the bytes are zeroes, i.e.:

xmlHeader = unpack("C*", pack("L", 260));
print_r(xmlHeader);

gives:

Array
(
    [1] => 4
    [2] => 1
    [3] => 0
    [4] => 0
)
ohho
  • 50,879
  • 75
  • 256
  • 383
  • Not a dupe, but have you looked at this question & answer thread? I am assuming the `4-byte` array you are referring to is the BOM? http://stackoverflow.com/questions/1772321/what-is-xml-bom-and-how-do-i-detect-it – Giacomo1968 Jan 07 '14 at 04:45
  • 1
    @JakeGould It's not the BOM. It's the header bytes hinting upcoming message length. – ohho Jan 08 '14 at 03:50

1 Answers1

0

PHP supports binary string:

$messageHead = pack("L", 260);
socket_write($socket, $messageHead, strlen($messageHead));

For 4-byte array ar:

$messageHead = pack("CCCC", $ar[1], $ar[2], $ar[3], $ar[4]);
ohho
  • 50,879
  • 75
  • 256
  • 383