<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = 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 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.unpack.php',
    1 => 'unpack',
    2 => 'Entpackt die Daten einer bin&auml;re Zeichenkette',
  ),
  'up' => 
  array (
    0 => 'ref.misc.php',
    1 => 'Sonstige Funktionen',
  ),
  'prev' => 
  array (
    0 => 'function.uniqid.php',
    1 => 'uniqid',
  ),
  'next' => 
  array (
    0 => 'function.usleep.php',
    1 => 'usleep',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'de',
    'path' => 'reference/misc/functions/unpack.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.unpack" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">unpack</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">unpack</span> &mdash; <span class="dc-title">Entpackt die Daten einer binäre Zeichenkette</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.unpack-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>unpack</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$format</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$offset</code><span class="initializer"> = 0</span></span>): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   Überträgt die Daten einer binäre Zeichenkette in ein Array unter
   Berücksichtigung des Parameters <code class="parameter">format</code>.
  </p>
  <p class="para">
   Die entpackten Daten werden in einem assoziativen Array abgebildet. Hierzu
   müssen die verschiedenen Format-Codes benannt und mit &quot;/&quot; getrennt werden.
   Wenn ein sich wiederholendes Argument existiert, werden die Array-Schlüssel
   durchnummeriert, indem ihnen eine Zahl angehängt wird.
  </p>
  <p class="para">
   Änderungen wurden durchgeführt, um diese Funktion in Übereinstimmung mit
   Perl zu bringen:
   <ul class="simplelist">
    <li>
     Der Code "a" erhält nun abschließende NULL Bytes.
    </li>
    <li>
     Der Code "A" entfernt nun alle abschließenden ASCII Whitespaces
     (Leerzeichen, Tabs, Zeilenvorschübe, Wagenrückläufe und NULL Bytes).
    </li>
    <li>
     Der Code "Z" wurde für mit NULL aufgefüllte Zeichenketten hinzugefügt,
     und entfernt abschließende NULL Bytes.
    </li>
   </ul>
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.unpack-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">format</code></dt>
     <dd>
      <p class="para">
       Die Format-Codes werden unter <span class="function"><a href="function.pack.php" class="function">pack()</a></span> näher
       erläutert.
      </p>
     </dd>
    
    
     <dt><code class="parameter">string</code></dt>
     <dd>
      <p class="para">
       Die gepackten Daten.
      </p>
     </dd>
    
    
     <dt><code class="parameter">offset</code></dt>
     <dd>
      <p class="para">
       Der Offset, an dem das Entpacken beginnt.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.unpack-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">
   Gibt ein assoziatives Array zurück, das die entpackten Elemente als binäre
   Zeichenkette enthält. Bei einem Fehler wird <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> zurückgegeben.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.unpack-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Beschreibung</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.2.0</td>
       <td>
        <span class="type"><a href="language.types.float.php" class="type float">float</a></span>- und <span class="type"><a href="language.types.float.php" class="type double">double</a></span>-Typen unterstützen sowohl
        Big-Endian als auch Little-Endian.
       </td>
      </tr>

      <tr>
       <td>7.1.0</td>
       <td>
        Der optionale <code class="parameter">offset</code> wurde hinzugefügt.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.unpack-examples">
  <h3 class="title">Beispiele</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Beispiel #1 <span class="function"><strong>unpack()</strong></span>-Beispiel</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$binarydata </span><span style="color: #007700">= </span><span style="color: #DD0000">"\x04\x00\xa0\x00"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$array </span><span style="color: #007700">= </span><span style="color: #0000BB">unpack</span><span style="color: #007700">(</span><span style="color: #DD0000">"cchars/nint"</span><span style="color: #007700">, </span><span style="color: #0000BB">$binarydata</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$array</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Array
(
    [chars] =&gt; 4
    [int] =&gt; 160
)</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Beispiel #2 <span class="function"><strong>unpack()</strong></span>-Beispiel mit Wiederholer</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$binarydata </span><span style="color: #007700">= </span><span style="color: #DD0000">"\x04\x00\xa0\x00"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$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">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$array</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Array
(
    [chars1] =&gt; 4
    [chars2] =&gt; 0
    [int] =&gt; 40960
)</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.unpack-notes">
  <h3 class="title">Anmerkungen</h3>
  <div class="caution"><strong class="caution">Achtung</strong>
   <p class="para">
    Beachten Sie, dass PHP Integer-Werte intern mit Vorzeichen speichert. Wenn
    Sie einen großen vorzeichenlosen Longwert entpacken und er von der selben
    Größe ist, die PHP für dessen Speicherung verwendet, wird das Ergebnis ein
    negativer Wert sein (auch wenn Sie dieses als vorzeichenlos zu entpacken
    angegeben haben).
   </p>
  </div>
  <div class="caution"><strong class="caution">Achtung</strong>
   <p class="para">
    Wird ein Element nicht benannt, dann werden numerische Indizes beginnend
    mit <code class="literal">1</code> verwendet. Es ist zu berücksichtigen, dass im
    Falle mehrerer unbenannter Elemente ein Teil der Daten überschrieben wird,
    da die Nummerierung für jedes Element wieder bei <code class="literal">1</code>
    beginnt.
   </p>
   <p class="para">
    <div class="example" id="example-3">
     <p><strong>Beispiel #3 <span class="function"><strong>unpack()</strong></span>-Beispiel mit unbenannten Schlüsseln</strong></p>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$binarydata </span><span style="color: #007700">= </span><span style="color: #DD0000">"\x32\x42\x00\xa0"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$array </span><span style="color: #007700">= </span><span style="color: #0000BB">unpack</span><span style="color: #007700">(</span><span style="color: #DD0000">"c2/n"</span><span style="color: #007700">, </span><span style="color: #0000BB">$binarydata</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$array</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
     </div>

     <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p></div>
     <div class="example-contents screen">
<div class="notescode"><pre class="notescode">array(2) {
  [1]=&gt;
  int(160)
  [2]=&gt;
  int(66)
}</pre>
</div>
     </div>
     <div class="example-contents"><p>
      Es ist zu beachten, dass der erste Wert vom Symbol <code class="literal">c</code>
      mit dem Wert vom Symbol <code class="literal">n</code> überschrieben wurde.
     </p></div>
    </div>
   </p>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.unpack-seealso">
  <h3 class="title">Siehe auch</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.pack.php" class="function" rel="rdfs-seeAlso">pack()</a> - Packt Daten in eine bin&auml;re Zeichenkette</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>