Open In App

PHP | pack() Function

The pack() function is an inbuilt function in PHP which is used to pack the given parameter into a binary string in a given format.

Syntax:



pack( $format, $arguments )

Parameters: This function accepts two parameters as mentioned above and described below:

Return Value: It returns a binary string containing data.



Note: This function is available on PHP 4.0.0 and newer version.

Program 1: This program uses C format to format the input parameter.




<?php
echo pack("C13", 71, 69, 69, 75, 83, 70, 79, 82, 71, 69, 69, 75, 83);
?>

Output:
GEEKSFORGEEKS

Program 2: This program uses A format to format the input parameter.




<?php
echo pack("A3", 71898);
?>

Output:
718

Program 3: This program uses i format to format the input parameter.




<?php
echo pack("i3", 56, 49, 54);
?>

Output:
816

Reference: https://www.php.net/manual/en/function.pack.php


Article Tags :