3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo alphaID('B3333V', true, 6, '3gmgkvj0jw8hrkcnu'); function alphaID($in, $to_num = false, $pad_up = false, $pass_key = null) { $out = ''; $index = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $base = strlen($index); if ($pass_key !== null) { // Although this function's purpose is to just make the // ID short - and not so much secure, // with this patch by Simon Franz (http://blog.snaky.org/) // you can optionally supply a password to make it harder // to calculate the corresponding numeric ID $i = str_split($index); $pass_hash = hash('sha256',$pass_key); $pass_hash = (strlen($pass_hash) < strlen($index) ? hash('sha512', $pass_key) : $pass_hash); $pass_hash = substr($pass_hash, 0, strlen($index)); $p = str_split($pass_hash); array_multisort($p, SORT_DESC, $i); $index = implode($i); } if ($to_num) { // Digital number <<-- alphabet letter code $len = strlen($in) - 1; for ($t = $len; $t >= 0; $t--) { $bcp = bcpow($base, $len - $t); $out = $out + strpos($index, substr($in, $t, 1)) * $bcp; } if (is_numeric($pad_up)) { $pad_up--; if ($pad_up > 0) { $out -= pow($base, $pad_up); } } } else { // Digital number -->> alphabet letter code if (is_numeric($pad_up)) { $pad_up--; if ($pad_up > 0) { $in += pow($base, $pad_up); } } for ($t = ($in != 0 ? floor(log($in, $base)) : 0); $t >= 0; $t--) { $bcp = bcpow($base, $t); $a = floor($in / $bcp) % $base; $out = $out . substr($index, $a, 1); $in = $in - ($a * $bcp); } } return $out; }
Output for 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Fatal error: Uncaught TypeError: Unsupported operand types: string + int in /in/fKK50:28 Stack trace: #0 /in/fKK50(3): alphaID('B3333V', true, 6, '3gmgkvj0jw8hrkc...') #1 {main} thrown in /in/fKK50 on line 28
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: Uncaught TypeError: Unsupported operand types: string + int in /in/fKK50:28 Stack trace: #0 /in/fKK50(3): alphaID('B3333V', true, 6, '3gmgkvj0jw8hrkc...') #1 {main} thrown in /in/fKK50 on line 28
Process exited with code 255.
Output for 7.3.32 - 7.3.33, 7.4.33, 8.0.13
Fatal error: Uncaught Error: Call to undefined function bcpow() in /in/fKK50:27 Stack trace: #0 /in/fKK50(3): alphaID('B3333V', true, 6, '3gmgkvj0jw8hrkc...') #1 {main} thrown in /in/fKK50 on line 27
Process exited with code 255.
Output for 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.32
Warning: A non-numeric value encountered in /in/fKK50 on line 28 7
Output for 5.6.0 - 5.6.38, 7.0.0 - 7.0.33
7
Output for 5.5.0 - 5.5.38
Fatal error: Call to undefined function bcpow() in /in/fKK50 on line 27
Process exited with code 255.

preferences:
205.53 ms | 401 KiB | 294 Q