3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gdr_encode($val) { $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!='; $base = strlen($chars); $str = ''; while ($val > 0) { $str = $chars[$val % $base] . $str;$val = (int)($val / $base); } return $str; } function gdr_decode($str) { $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!='; $base = strlen($chars); $map = array(); for ($i=0; $i<$base; $i++) { $map[$chars[$i]] = $i; } $val = 0; for ($i=0; $i<strlen($str); $i++) { $val *= $base; $val += (int)$map[$str[$i]]; } return $val; } $vals = array(0, 1, 99, 100, 255, 256, 999, 1000, 9999, 10000, 65535, 65536, 99999, 100000, 999999, 1000000, 1023410115, 4294967295, 4294967296); foreach ($vals as $val) { $enc = gdr_encode($val); $dec = gdr_decode($enc); if (strlen($enc)+2 > strlen($val)) { echo "\"$enc\" $val WORSE\n"; } else if (strlen($enc)+2 == strlen($val)) { echo "\"$enc\" $val EQUAL\n"; } else { echo "\"$enc\" $val\n"; } }
Output for 5.4.0 - 5.4.31
Parse error: syntax error, unexpected '$str' (T_VARIABLE) in /in/H2pbu on line 8
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected T_VARIABLE in /in/H2pbu on line 8
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_VARIABLE in /in/H2pbu on line 8
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/H2pbu on line 8
Process exited with code 255.

preferences:
228.14 ms | 1395 KiB | 122 Q