3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function gdr_encode($val) { $bin = ''; while ($val > 0) { $bin .= chr($val & 0xFF); $val >>= 8; } return str_replace(array('/', '='), array('_', ''), base64_encode($bin)); } function gdr_decode($str) { $bin = base64_decode(str_replace('_', '/', $str)); $val = 0; for ($i=strlen($bin)-1; $i>=0; $i--) { $val |= ord($bin[$i]) << $i*8; } return $val; } function test_enc($val) { $enc = gdr_encode($val); $dec = gdr_decode($enc); if ($val === $dec) { echo "$enc $val\n"; } else { echo "$enc $val ERROR: gdr_decode($enc) == $dec\n"; } } foreach (array(0, 1, 99, 100, 255, 256, 999, 1000, 9999, 10000, 65535, 65536, 99999, 100000, 999999, 1000000, 4294967295, 4294967296) as $val) { test_enc($val); }echo "\n"; /* // seed rng for consistent values if (phpversion() < '5.2.1') { die('old rng'); } mt_srand(42); for ($i=0; $i<63; $i++) { $val = 1<<$i; $val += mt_rand(0, $val/2); test_enc($val); } */
based on PftrC
Output for 5.0.4 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Notice: Use of undefined constant  65535 - assumed ' 65535' in /in/Q2IYF on line 31 Notice: Use of undefined constant  65536 - assumed ' 65536' in /in/Q2IYF on line 31 Notice: Use of undefined constant  4294967295 - assumed ' 4294967295' in /in/Q2IYF on line 31 Notice: Use of undefined constant  4294967296 - assumed ' 4294967296' in /in/Q2IYF on line 31 0 AQ 1 Yw 99 ZA 100 _w 255 AAE 256 5wM 999 6AM 1000 Dyc 9999 ECc 10000 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0 n4YB 99999 oIYB 100000 P0IP 999999 QEIP 1000000 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0
Output for 4.3.0 - 5.0.3
Notice: Use of undefined constant  65535 - assumed ' 65535' in /in/Q2IYF on line 31 Notice: Use of undefined constant  65536 - assumed ' 65536' in /in/Q2IYF on line 31 Notice: Use of undefined constant  4294967295 - assumed ' 4294967295' in /in/Q2IYF on line 31 Notice: Use of undefined constant  4294967296 - assumed ' 4294967296' in /in/Q2IYF on line 31 0 AQ 1 Yw 99 ZA 100 _w 255 AAE 256 5wM 999 6AM 1000 Dyc 9999 ECc 10000 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0 n4YB 99999 oIYB 100000 P0IP 999999 QEIP 1000000 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0 Notice: Undefined variable: val ERROR in /in/Q2IYF on line 27 : gdr_decode() == 0