CopyPastehas never been so tasty!

Unpack values using unpack () in PHP

by anonymous

  • 0
  • 0
  • 0
72 views

http://codingvilla.com/unpack-values-using-unpack-php-single-article-665.aspx

In this simple article you will learn that how we can unpack values using unpack () in PHP.

Binary String:

It is a sequence of bytes. Binary string holds non-traditional data like picture; voice etc. character string holds textual data but binary string holds non-traditional data.

Unpack () function:

Unpack is used to unpack binary data. It unpacks the binary string data in a specific format.

Syntax:

Unpack(format,data)

Format: is used to specify the format when data is unpack

Data: that is going to be unpack


Unpack values using unpack () function in PHP:

To unpack binary data we use unpack () function in php. It is a built-in function in php that unpacks the binary string data into specific format. This function takes format and data as a parameter and return unpack data in a specific format. In the given code we have send data as a parameter and unpack it in integer form.


Code:


<?php
$data = "PHP";
print_r(unpack("C*myint",$data));
?>


Output:


Array
(
[myint1] => 80
[myint2] => 72
[myint3] => 80
)


Another code:


<?php
$data = "PHP";
print_r(unpack("C*",$data));
?>


Output:


Array
(
[1] => 80
[2] => 72
[3] => 80s



This is simple code for unpacking data using unpack () function in php.

This simple article tells that how we can unpack data using unpack () function in php.

Add A Comment: