switch
switch

Reputation: 73

What is Unpack's "binary string"

I'm trying to the unpack function. The PHP documentation says

Unpacks from a binary string into an array according to the given format.

Does the string passed have to be a binary string? and what exactly is a binary string?

Upvotes: 0

Views: 441

Answers (2)

Mark Tomlin
Mark Tomlin

Reputation: 8933

A binary string just means data that is in it's base binary format. The data it's self is being displayed as a string to you if you where to echo it, but it would be meaningless without applying it's correct structure to it. So for example a number would not look like a number, because it's in binary. While the data is there, it has to be parsed as a number for it to be readable as a number otherwise it could look like 'abcd'.

Upvotes: 1

dogmatic69
dogmatic69

Reputation: 7575

if you read down slightly further you will see examples of what binary strings look like

$binarydata = "\x32\x42\x00\xa0";

Also the description of the method clearly says Unpacks from a binary string, so yes it requires a binary string.

more information on binary

Upvotes: 0

Related Questions