3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function gdr_encode($val) { $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!='; $base = strlen($chars); $str = ''; while ($val > 0) { $str .= $chars[$val % $base]; $val = int($val / $chars); } return $str; } function gdr_decode($val) { return base_convert(strval($val), 16, 10); } $vals = array(0, 1, 99, 100, 255, 256, 999, 1000, 9999, 10000, 65535, 65536, 99999, 100000, 999999, 1000000, 4294967295, 4294967296); foreach ($vals as $val) { $enc = json_encode(gdr_encode($val)); $dec = json_encode(gdr_decode($enc)); $val = json_encode($val); if (strlen($enc) > strlen($val)) { echo "$enc $val WORSE\n"; } else if (strlen($enc) == strlen($val)) { echo "$enc $val EQUAL\n"; } else { echo "$enc $val\n"; } }
based on I2SK5
Output for 5.4.0 - 5.4.31
Parse error: syntax error, unexpected ''ABCDEFGHIJKLMNOPQRSTUVWXYZabc' (T_CONSTANT_ENCAPSED_STRING) in /in/iQKtB on line 4
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /in/iQKtB on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /in/iQKtB on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/iQKtB on line 4
Process exited with code 255.