Search code examples
phppack

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*.


Solution

  • 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).