Load data into a binary string:
<?phpecho pack("C3",80,72,80);?>The pack() function loads data into a binary string.
pack( format,args+ )
parameter | describe |
---|---|
format | Required. Specifies the format used when packaging data. Possible values: a - a NUL padded string A - SPACE filled string h - Hexadecimal string, low-order bit first H - Hexadecimal string, high-order bit first c - signed char C - unsigned char s - signed short (always 16 bits, machine byte order) S - unsigned short (always 16 bits, machine byte order) n - unsigned short (always 16 bits, big endian byte order) v - unsigned short (always 16 bits, little endian byte order) i - signed integer (depends on machine size and byte order) I - unsigned integer (depends on machine size and byte order) l - signed long (always 32 bits, machine byte order) L - unsigned long (always 32 bits, machine byte order) N - unsigned long (always 32 bits, big endian byte order) V - unsigned long (always 32 bits, little endian byte order) f - float (depends on machine size and representation) d - double (depends on machine size and representation) x - NUL byte X - Back up one byte Z - NUL padded string @ - NUL fills the absolute position |
args+ | Optional. Specifies one or more parameters to be wrapped. |
Return value: | Returns a binary string containing the data. |
---|---|
PHP version: | 4+ |
Update log: | There is a new "Z" code in PHP 5.5, which has the same functionality as "a" for Perl compatibility. |
Load data into a binary string:
<?phpecho pack("C*",80,72,80);?>