Source of: /manual/en/function.unpack.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.misc.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'function.unpack.php',
1 => 'unpack',
),
'up' =>
array (
0 => 'ref.misc.php',
1 => 'Misc. Functions',
),
'prev' =>
array (
0 => 'function.uniqid.php',
1 => 'uniqid',
),
'next' =>
array (
0 => 'function.usleep.php',
1 => 'usleep',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="function.unpack" class="refentry">
<div class="refnamediv">
<h1 class="refname">unpack</h1>
<p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">unpack</span> — <span class="dc-title">Unpack data from binary string</span></p>
</div>
<a name="function.unpack.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type">array</span> <span class="methodname"><b>unpack</b></span>
( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$format</tt></span>
, <span class="methodparam"><span class="type">string</span> <tt class="parameter">$data</tt></span>
)</div>
<p class="para rdfs-comment">
Unpacks from a binary string into an array according to the given
<i><tt class="parameter">format</tt></i>
.
</p>
<p class="para">
<b>unpack()</b> works slightly different from Perl as
the unpacked data is stored in an associative array. To
accomplish this you have to name the different format codes and
separate them by a slash /.
</p>
</div>
<a name="function.unpack.parameters"></a><div class="refsect1 parameters">
<h3 class="title">Parameters</h3>
<p class="para">
</p><dl>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">format</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
See <a href="function.pack.php" class="function">pack()</a> for an explanation of the format codes.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">data</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The packed data.
</p>
</dd>
</dl>
<p>
</p>
</div>
<a name="function.unpack.returnvalues"></a><div class="refsect1 returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
Returns an associative array containing unpacked elements of binary
string.
</p>
</div>
<a name="function.unpack.examples"></a><div class="refsect1 examples">
<h3 class="title">Examples</h3>
<p class="para">
</p><div class="example">
<p><b>Example #1 <b>unpack()</b> example</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br />$array </span><span style="color: #007700">= </span><span style="color: #0000BB">unpack</span><span style="color: #007700">(</span><span style="color: #DD0000">"c2chars/nint"</span><span style="color: #007700">, </span><span style="color: #0000BB">$binarydata</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
<div class="example-contents para"><p>
The resulting array will contain the entries "chars1",
"chars2" and "int".
</p></div>
</div><p>
</p>
</div>
<a name="function.unpack.notes"></a><div class="refsect1 notes">
<h3 class="title">Notes</h3>
<div class="caution"><b class="caution">Caution</b>
<p class="para">
Note that PHP internally stores integral values as signed. If you
unpack a large unsigned long and it is of the same size as PHP
internally stored values the result will be a negative number
even though unsigned unpacking was specified.
</p>
</div>
</div>
<a name="function.unpack.seealso"></a><div class="refsect1 seealso">
<h3 class="title">See Also</h3>
<p class="para">
</p><ul class="simplelist">
<li class="member"><a href="function.pack.php" class="function" rel="rdfs-seeAlso">pack()</a> - Pack data into binary string</li>
</ul><p>
</p>
</div>
</div><?php manual_footer(); ?>