3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Unicode/multibyte capable equivelant of ord(). function charCodeAt($a, $b) { $a = mb_convert_encoding($a,"UCS-4BE","UTF-8"); $c = unpack("N", mb_substr($a,$b,1,"UCS-4BE")); return $c[1]; } // strToNum - Convert a string into a 32-bit integer. function strToNum ($str, $c, $k) { $int32unit = 4294967296; // 2^32 for ($i=0; $i<strlen($str); $i++) { $c *= $k; if ($c >= $int32unit) { $c = ($c - $int32unit * (int)($c / $int32unit)); if (PHP_INT_MAX != 0x0000000080000000) { // 2147483647 $c = -(~($c & 0x00000000FFFFFFFF) + 1); } // if $c is less than -2^31 $c = ($c < 0x0000000080000000) ? ($c + $int32unit) : $c; } $c += charCodeAt($str, $i); } return $c; } 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 strToNum($str, 0x1505, 0x21); /* $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; */

preferences:
38.22 ms | 402 KiB | 5 Q