user1149244
user1149244

Reputation: 755

Need more details on PHP pack function

i have been trying to understand the pack function. I'm having trouble on this sort of code

pack( 'NNnNna*', $string);

what does NNnNna* mean? and also i saw others as axa* and a4xa*.

Upvotes: 0

Views: 2381

Answers (2)

Jon Egeland
Jon Egeland

Reputation: 12623

After googling "PHP pack", you'd find this on php.net.

Pack given arguments into binary string according to format.

The idea for this function was taken from Perl and all formatting codes work the same as in Perl. However, there are some formatting codes that are missing such as Perl's "u" format code.

Note that the distinction between signed and unsigned values only affects the function unpack(), where as function pack() gives the same result for signed and unsigned format codes.

There's also a lot of discussion on the bottom. (by the way, every PHP function, variable, object, etc., has documentation, change-logs, discussion, and related functions on php.net, so always check there first).

Upvotes: 3

Brianjs
Brianjs

Reputation: 2339

Try here if you haven't already, gives a good rundown on the pack function.

http://www.w3schools.com/php/func_misc_pack.asp

Some great examples on the bottom of the page

The pack() function packs data into a binary string. Syntax pack(format,args+)

Upvotes: 2

Related Questions