The pack of PHP's function

Source: Internet
Author: User

PHP does not attribute other categories of functions called Miscellaneous functions, also attributes PHP's core components

Pack ($format, arg+)//load data into a binary string

$format: Required to specify the format to use when wrapping data.
arg+: Optional, specify one or more parameters to be packaged

Possible values for $format parameters

a-nul-padded string

a-space-padded string

H-hex string, low nibble first

H-hex string, high nibble first

c-signed Char

c-unsigned Char

s-signed short (always the bit, machine byte order)

s-unsigned short (always the bit, machine byte order)

n-unsigned short (always the bit, big endian byte order)

v-unsigned short (always-on bit, little endian byte order)

i-signed integer (Machine dependent size and byte order)

i-unsigned integer (Machine dependent size and byte order)

L-signed long (always the bit, machine byte order)

L-unsigned long (always the bit, machine byte order)

N-unsigned long (always the bit, big endian byte order)

V-unsigned long (always the bit, little endian byte order)

F-float (Machine dependent size and representation)

D-double (Machine dependent size and representation)

X-nul byte

X-back up one byte

@-Nul-fill to absolute position

As an example:

Echo Pack ("S", +);    // If there is no data behind the format s or a specific number or *, then there can be only one argument later, if there is a specific number later, then the following argument is so many

P
Echo Pack  ("C3", 80,72,80); Indicates that there can be only 3 parameters at a later //PHP
$str NULL ;      for ($i= 0; $i<20; $i++)        {$strpack("S",mt_rand(80,128));    }     Echo $str ; // M{qxim^wslts_w[kvrsu
Echo Pack  ("c*", 80,72,80); // indicates that only 3 parameters can be followed//php

The pack of PHP's function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.