3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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; */
Output for 4.4.0 - 4.4.9, 5.0.5 - 7.1.0
4756089835
Output for 4.3.5 - 4.3.11, 5.0.0 - 5.0.4
Notice: Use of undefined constant PHP_INT_MAX - assumed 'PHP_INT_MAX' in /in/6Ojuc on line 15 Notice: Use of undefined constant PHP_INT_MAX - assumed 'PHP_INT_MAX' in /in/6Ojuc on line 15 Notice: Use of undefined constant PHP_INT_MAX - assumed 'PHP_INT_MAX' in /in/6Ojuc on line 15 4756089835
Output for 4.3.0 - 4.3.4
Notice: Undefined offset: 1 in /in/6Ojuc on line 6 Notice: Undefined offset: 1 in /in/6Ojuc on line 6 Notice: Undefined offset: 1 in /in/6Ojuc on line 6 Notice: Use of undefined constant PHP_INT_MAX - assumed 'PHP_INT_MAX' in /in/6Ojuc on line 15 Notice: Undefined offset: 1 in /in/6Ojuc on line 6 Notice: Use of undefined constant PHP_INT_MAX - assumed 'PHP_INT_MAX' in /in/6Ojuc on line 15 Notice: Undefined offset: 1 in /in/6Ojuc on line 6 Notice: Use of undefined constant PHP_INT_MAX - assumed 'PHP_INT_MAX' in /in/6Ojuc on line 15 Notice: Undefined offset: 1 in /in/6Ojuc on line 6 4427023557