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) { $Int32U = 4294967296; // 2^32 for ($i = 0; $i < mb_strlen($str); $i++) { $c *= $k; if ($c >= $Int32U) { $c = $c - ($Int32U * (int) ($c / $Int32U)); // if $c is less than -2^31 $c = ($c < 0x0000000080000000) ? ($c + $Int32U) : $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.3.5 - 7.1.0
4756089835
Output for 4.3.0 - 4.3.4
Notice: Undefined offset: 1 in /in/kQtYI on line 6 Notice: Undefined offset: 1 in /in/kQtYI on line 6 Notice: Undefined offset: 1 in /in/kQtYI on line 6 Notice: Undefined offset: 1 in /in/kQtYI on line 6 Notice: Undefined offset: 1 in /in/kQtYI on line 6 Notice: Undefined offset: 1 in /in/kQtYI on line 6 4427023557