I have a WebSocket
encoder:
print_r(frameEncode("How can I convert a byteArray to String in PHP?"));
function frameEncode($message) {
$messageBytes = array();
$messageLength = strlen($message);
$messageBytes[0] = 129;
if ($messageLength < 126) {
$messageBytes[1] = $messageLength;
} else if ($messageLength <= 65535) {
$messageBytes[1] = 126;
$messageBytes[2] = ($messageLength >> 8) & 255;
$messageBytes[3] = $messageLength & 255;
} else {
$messageBytes[1] = 127;
$messageBytes[2] = ($messageLength >> 56) & 255;
$messageBytes[3] = ($messageLength >> 48) & 255;
$messageBytes[4] = ($messageLength >> 40) & 255;
$messageBytes[5] = ($messageLength >> 32) & 255;
$messageBytes[6] = ($messageLength >> 24) & 255;
$messageBytes[7] = ($messageLength >> 16) & 255;
$messageBytes[8] = ($messageLength >> 8) & 255;
$messageBytes[9] = $messageLength & 255;
}
return pack("C*", $messageBytes) . $message;
}
How can I convert the $messageBytes
to a string at the end of the function? The array values are simply getting ignored by pack()
.