<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.strings.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.crc32.php',
    1 => 'crc32',
    2 => 'Berechnet den polynomischen CRC32-Wert eines Strings',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'String-Funktionen',
  ),
  'prev' => 
  array (
    0 => 'function.count-chars.php',
    1 => 'count_chars',
  ),
  'next' => 
  array (
    0 => 'function.crypt.php',
    1 => 'crypt',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'de',
    'path' => 'reference/strings/functions/crc32.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.crc32" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">crc32</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.1, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">crc32</span> &mdash; <span class="dc-title">Berechnet den polynomischen CRC32-Wert eines Strings</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.crc32-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>crc32</strong></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="type"><a href="language.types.integer.php" class="type int">int</a></span></div>

  <p class="para rdfs-comment">
   Berechnet die zyklisch redundante polynomische Prüfsumme mit einer
   Länge von 32 Bit für <code class="parameter">string</code>. Dies wird gewöhnlich
   für die Integritätsprüfung übermittelter Daten verwendet.
  </p>
  <div class="warning"><strong class="warning">Warnung</strong>
   <p class="simpara">
    Da der Datentyp Integer von PHP vorzeichenbehaftet (&quot;signed&quot;) ist,
    resultieren viele Prüfsummen auf 32bit Plattformen in negativen
    Integer-Werten. In 64bit Installationen sind jedoch alle
    <span class="function"><strong>crc32()</strong></span>-Ergebnisse positive Ganzzahlen.
   </p>
   <p class="simpara">
    Daher ist die &quot;%u&quot; Typangabe von <span class="function"><a href="function.sprintf.php" class="function">sprintf()</a></span> oder
    <span class="function"><a href="function.printf.php" class="function">printf()</a></span> nötig, um die Stringrepräsentation der
    vorzeichenlosen <span class="function"><strong>crc32()</strong></span>-Prüfsumme im Dezimalformat zu
    erhalten.
   </p>
   <p class="simpara">
    Für die hexadezimale Repräsentation der Prüfsumme kann entweder
    die &quot;%x&quot; Typangabe von <span class="function"><a href="function.sprintf.php" class="function">sprintf()</a></span> oder
    <span class="function"><a href="function.printf.php" class="function">printf()</a></span> oder die
    <span class="function"><a href="function.dechex.php" class="function">dechex()</a></span>-Umwandlungsfunktion verwendet werden; beide
    sorgen für die Konvertierung des
    <span class="function"><strong>crc32()</strong></span>-Ergebnisses in eine vorzeichenlose Ganzzahl.
   </p>
   <p class="simpara">
    Es wurde in Erwägung gezogen, auch in 64bit-Installationen negative
    Ganzzahlen für höhere Ergebniswerte zurückzugeben, aber das hätte die
    Hexadezimalumwandlung ruiniert, da dann negative Ganzzahlen ein zusätzliches
    0xFFFFFFFF########-Offset erhielten. Da die hexadezimale Repräsentation der
    meist verbreitete Anwendungsfall scheint, wurde entschieden das nicht zu
    tun, auch wenn es direkte dezimale Vergleiche in etwa 50% der Fälle
    ruiniert, wenn von 32bit auf 64bit gewechselt wird.
   </p>
   <p class="simpara">
    Die Funktion eine Ganzzahl zurückgeben zu lassen, war im Nachhinein gesehen
    möglicherweise nicht die beste Idee, und gleich einen Hex-String
    zurückzugeben (wie z. B. <span class="function"><a href="function.md5.php" class="function">md5()</a></span>) könnte gleich zu Anfang
    ein besserer Plan gewesen sein.
   </p>
   <p class="simpara">
    Für eine portablere Lösung ist das generische <span class="function"><a href="function.hash.php" class="function">hash()</a></span> in
    Erwägung zu ziehen. <code class="code">hash(&quot;crc32b&quot;, $str)</code> liefert die gleiche
    Zeichenkette wie <code class="code">str_pad(dechex(crc32($str)), 8, &#039;0&#039;, STR_PAD_LEFT)</code>.
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.crc32-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">string</code></dt>
     <dd>
      <p class="para">
       Die Daten.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.crc32-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">
   Gibt die CRC32-Prüfsumme von <code class="parameter">string</code> als Integer
   zurück.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.crc32-examples">
  <h3 class="title">Beispiele</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Beispiel #1 Anzeigen einer CRC32-Prüfsumme</strong></p>
    <div class="example-contents"><p>
     Das folgende Beispiel zeigt, wie eine konvertierte Prüfsumme mittels der
     Funktion <span class="function"><a href="function.printf.php" class="function">printf()</a></span> ausgegeben wird:
    </p></div>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$pruefsumme </span><span style="color: #007700">= </span><span style="color: #0000BB">crc32</span><span style="color: #007700">(</span><span style="color: #DD0000">"Der schnelle braune Fuchs sprang über den trägen Hund."</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%u\n"</span><span style="color: #007700">, </span><span style="color: #0000BB">$pruefsumme</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.crc32-seealso">
  <h3 class="title">Siehe auch</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.hash.php" class="function" rel="rdfs-seeAlso">hash()</a> - Berechnet den Hash einer Nachricht</span></li>
    <li><span class="function"><a href="function.md5.php" class="function" rel="rdfs-seeAlso">md5()</a> - Errechnet den MD5-Hash eines Strings</span></li>
    <li><span class="function"><a href="function.sha1.php" class="function" rel="rdfs-seeAlso">sha1()</a> - Berechnet den SHA1-Hash eines Strings</span></li>
   </ul>
  </p>
 </div>


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