- sha1: documentation ( source)
- date: documentation ( source)
- preg_replace: documentation ( source)
<?php
function string_inthash($str)
{
$a = (int)preg_replace('#[^0-9]#u', '', sha1($str)) * (int)date('YmdHis');
if (PHP_INT_MAX != 0x0000000080000000) { // 2147483647
$a = -(~($a & 0x00000000FFFFFFFF) + 1);
}
return (int)$a;
}
$str = 'secret';
echo string_inthash($str);
/*
$a = date('YmdHi');
$b = 'secret';
$bb = sha1($b);
$bc = preg_replace('#[^0-9]#u', '', $bb);
$bd = (int)$bc - (int)$a;
$c = "{$b}|{$a}";
$d = base64_encode($c);
$e = base64_decode($d);
echo $a . PHP_EOL;
echo $b . PHP_EOL;
echo $bb . PHP_EOL;
echo $bc . PHP_EOL;
echo $bd . PHP_EOL;
echo $c . PHP_EOL;
echo $d . PHP_EOL;
echo $e . PHP_EOL;
*/