3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php define('ALPHABET', 'acdegilmnoprstuw'); $hash = 680131659347; $string = 'leepadg'; echo sprintf('Hash of string «%s» is «%s».', $string, get_hash(ALPHABET, $string)), PHP_EOL , sprintf('String of hash «%s» is «%s».', $hash, unhash(ALPHABET, $hash)) ; function get_hash($alphabet, $string) { $h = 7; $len = strlen($string); for($i = 0; $i < $len; $i++) { $h = ($h * 37 + strpos($alphabet, $string[$i])); } return $h; } function unhash($alphabet, $hash) { $result = ''; $len = strlen($letters); while ($res > 7) { for ($i = 0; $i < $len; $i++) { $newres = ($res - $i) / 37; if (is_int($newres)) { $result .= $letters[$i]; $res = $newres; break; } } return strrev($result); } }
based on Dl9mE
Output for 5.0.4 - 7.2.0
Hash of string «leepadg» is «680131659347». Notice: Undefined variable: letters in /in/Hbl18 on line 25 Notice: Undefined variable: res in /in/Hbl18 on line 26 String of hash «680131659347» is «».
Output for 4.3.10 - 4.4.9, 5.0.2 - 5.0.3
Hash of string «leepadg» is «680131659347». Notice: Undefined variable: letters in /in/Hbl18 on line 25 Notice: Undefined variable: res in /in/Hbl18 on line 26 String of hash «680131659347» is «».
Output for 4.3.0 - 4.3.9, 5.0.0 - 5.0.1
Hash of string «leepadg» is «680131659347». Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/Hbl18 on line 9 PHP_EOL Notice: Undefined variable: letters in /in/Hbl18 on line 25 Notice: Undefined variable: res in /in/Hbl18 on line 26 String of hash «680131659347» is «».