Syntax:pack ($format, $arguments)
Parameters:this function takes two parameters as specified above and described below:
- $format:required. It defines the format to be used when packing data. Possible format values:
- a- NUL-padded string
- A- line with space
- h- low hex first hex line
- H- high hex first hex line
- c- signed character
- C- unsigned character
- s- short signature (16 bit, machine byte order)
- S- unsigned short (16 bit, machine byte order)
- n- unsigned short (16 bit, big endian byte order)
- v- unsigned short (16 bit, big endian byte order)
- i- signed integer (machine dependent byte order and size)
- I- unsigned integer (machine dependent byte order and size)
- l- long signature (32 bits, machine byte order)
- L- unsigned long (32 bit, machine byte order)
- N- unsigned long (32 bit, big endian byte order)
- V- unsigned long (32-bit, big endian byte order)
- f- float (machine dependent representation and size)
- d- double (machine-dependent representation and size)
- x- NUL bytes
- X- Back up one byte
- Z- NUL-padded string
- @- NUL-fill to absolute position
- $arguments:This is an optional parameter. It specifies one or more arguments to pack.
Return Value:Returns a binary string containing data.
Note. This function is available in PHP 4.0.0 and later.
Program 1:This program uses the
Cformat to format the input parameter.
echo
pack (
"C13"
, 71, 69, 69, 75, 83, 70, 79, 82, 71, 69, 69, 75, 83);
?>
Exit:GEEKSFORGEEKS Program 2:This program uses the Aformat to format the input parameter. echo
pack (
"A3"
, 71898);
?>
Exit:718 Program 3:This program uses the iformat to format the input parameter. echo
pack (
"i3"
, 56, 49, 54);
?>
Exit:816 Link: https://www. php.net/manual/en/function.pack.php