note 63254 deleted from function.crc32 by nlopess
| From: | nlopess@php.net | Date: | Wed, 17 Jan 2007 23:14:02 +0000 |
| Subject: | note 63254 deleted from function.crc32 by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-121865@lists.php.net to get a copy of this message | ||
Note Submitter: administrador(ensaimada)sphoera(punt)com
----
To obtain the adler32 hash from a string, you can use this simple function:
<?php
function adler32($buf){
$low = 1;
$high = 0;
$len = strlen($buf);
for ($n = 0; $n < $len; $n++) {
$low = ($low + ord($buf[$n])) % 65521;
$high = ($high + $low) % 65521;
}
$crc = $high * 65536 + $low;
return $crc;
}
// and for entire files:
function file_adler32($filename){
return adler32(file_get_contents($filename));
}
?>
more functions at http://www.sphoera.com/