note 72670 modified in function.hash by danbrown
| From: | danbrown@php.net | Date: | Sat, 14 Mar 2009 14:50:05 +0000 |
| Subject: | note 72670 modified in function.hash by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-151897@lists.php.net to get a copy of this message | ||
If the hash functions are not available to you at the moment, and you want to future proof your
code, then the code below will emulate two of the important hashing functions, they will also be
automatically replaced with the faster versions if available.
<?php
if(!function_exists('hash_algos'))
{
function hash_algos()
{
$algo[0] = "md5";
$algo[1] = "sha1";
$algo[2] = "crc32";
return($algo);
}
}
if(!function_exists('hash'))
{
function hash($algo, $data, $raw_output = 0)
{
if($algo == 'md5') return(md5($data));
if($algo == 'sha1') return(sha1($data));
if($algo == 'crc32') return(crc32($data));
}
}
?>
--was--
If the hash functions are not available to you at the moment, and you want to future proof your
code, then the code below will emulate two of the important hashing functions, they will also be
automatically replaced with the faster versions if available.
if(!function_exists('hash_algos'))
{
function hash_algos()
{
$algo[0] = "md5";
$algo[1] = "sha1";
$algo[2] = "crc32";
return($algo);
}
}
if(!function_exists('hash'))
{
function hash($algo, $data, $raw_output = 0)
{
if($algo == 'md5') return(md5($data));
if($algo == 'sha1') return(sha1($data));
if($algo == 'crc32') return(crc32($data));
}
}
http://php.net/manual/en/function.hash.php