Miscellaneous Functions Library: Pack

Source: Internet
Author: User
Keywords PHP Chinese function manual miscellaneous function library
Tags aliyun binary code data function function library functions html

Pack

(PHP3, PHP4)

Pack---&http://www.aliyun.com/zixun/aggregation/37954.html ">nbsp; Parcel data into binary strings

Syntax: string pack (string format [, mixed args ...])

Description:

The parameters given by the package in the parameter format become binary strings, and the binary strings are returned.

The concept of this function is taken from Perl, and all format codes (formatting code) are the same, but there is a lack of some format code, such as Perl's "U" format code. The format string is composed of a format code, followed by an repeater parameter that is not required, and the repeater parameter can be an integer value or a *. When the parameter format is a, a, H, H, repeat calculates how many characters a data parameter takes. When the parameter format is @, it is an absolute position to place the next data. Otherwise, repeat calculates the specified consumption (consumed) data parameter and wraps it into a binary string. Current format formats are:

A--null padding string

A--Space padding string

H--16-digit string, starting as low character

H--16 carry string, starting as high character

C--Symbol character

C--Unsigned strings

S--Symbol short (always 16-bit, machine-bit order)

S--Unsigned short (always 16-bit, machine-bit order)

N--unsigned short (always a 16-bit, large-byte order in the end of the word)

V--Unsigned short (always a 16-bit, small bit-tuple in the order of the end of the word)

I--symbolic integers (machine dependent on size and bit order)

I--unsigned integers (machine dependent on size and bit order)

L--Symbol long Integer (always 32-bit, machine-bit order)

L--unsigned long integers (always 32 bits, machine bit order)

N--unsigned long integers (always a 32-bit, large-byte order in the end of the word)

V--unsigned long integers (always 32 bits, small bits in the order of the end of the word)

F--floating-point number (machine depends on size and representation)

D--Times floating-point number (machine depends on size and representation)

X--NULL bit tuple

X--Back up a bit

@--fill null to absolute position

Example:

<?php

$binarydata = Pack ("nvc*", 0x1234, 0x5678, 65, 66);

?>

The result of the binary string will be the 6-bit leader and contain the sequence of bytes 0x12, 0x34, 0x78, 0x56, 0x41, 0x42

Note: the pack () symbol and the unsigned difference only work for unpack ()

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.