3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gdr_encode($val) { // $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!='; // all characters that json_encode without escaping $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!='; // all characters that json_encode without escaping $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, 500000, 999999, 1000000, 4294967295, 4294967296); foreach ($vals as $val) { $enc = gdr_encode($val); $dec = gdr_decode($enc); if ($dec !== $val) { echo "ERROR: $val => $enc => $dec\n"; } else 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 git.master, git.master_jit, rfc.property-hooks
"" 0 WORSE "B" 1 WORSE "BH" 99 WORSE "BI" 100 WORSE "C*" 255 WORSE "C+" 256 WORSE "K=" 999 WORSE "K>" 1000 EQUAL "BQ!" 9999 WORSE "BQ#" 10000 EQUAL "H'f" 65535 EQUAL "H'g" 65536 EQUAL "L-`" 99999 EQUAL "L-{" 100000 "7G+" 500000 "BaNz" 999999 EQUAL "BaN0" 1000000 "7`7nL" 4294967295 "7`7nM" 4294967296

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
48.63 ms | 401 KiB | 8 Q