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; } if (phpversion() < '5.2.1') { die('old rng'); } // seed rng for consistent values mt_srand(42); for ($i=0; $i<32; $i++) { $val = 1<<$i; $val += mt_rand(0, $val/2); $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"; } }
based on iZC9n
Output for 7.1.0
AQ 1 Aw 3 BQ 5 DA 12 EA 16 Jg 38 WQ 89 uw 187 QAE 320 EQI 529 KAQ 1064 cgg 2162 tBU 5556 Ky0 11563 oUo 19105 wpc 38850 oXgB 96417 1cYC 181973 9uMF 386038 2nYI 554714 7QUV 1377773 Tfwg 2161741 P_tL 4979519 dOaU 9758324 QfQaAQ 18543681 rfxEAg 38075565 CttbBA 73128714 gQkzCA 137562497 uhSMFg 378279098 rJMBLg 771855276 E5nzTg 1324587283 nkQTng 2652062878
Output for 5.2.1 - 5.6.28, hhvm-3.10.0 - 3.13.2, 7.0.0 - 7.0.14
AQ 1 Aw 3 Bg 6 DA 12 Eg 18 Iw 35 TQ 77 mQ 153 FAE 276 cgI 626 swU 1459 nAs 2972 dxA 4215 sCg 10416 ZUQ 17509 _6o 43775 8UwB 85233 kyQC 140435 p5cE 300967 g5oK 694915 KCoQ 1059368 cg4v 3083890 gQlf 6228353 OzWu 11416891 j8YVAQ 18204303 _kTwAg 49300734 trdsBA 74233782 jpP6Cw 200971150 pmB0EQ 292839590 lWcJIA 537487253 InPeRQ 1172206370 kyshmA 2552310675
Output for 4.3.0 - 5.2.0
old rng