3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gdr_encode($val) { // all characters that json encode without escaping $chrs = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 !#$%&\'()*+,-.:;<=>?@[]^_`{|}~'; $base = strlen($chrs); $str = ''; while ($val > 0) { $str = $chrs[$val % $base] . $str; $val = (int)($val / $base); } return $str; } function gdr_decode($str) { // all characters that json encode without escaping $chrs = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 !#$%&\'()*+,-.:;<=>?@[]^_`{|}~'; $base = strlen($chrs); $map = array(); for ($i=0; $i<$base; $i++) { $map[$chrs[$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 { echo sprintf("%2d %7s %10d\n", strlen($enc)+2-strlen($val), "\"$enc\"", $dec);} }
Output for git.master, git.master_jit, rfc.property-hooks
1 "" 0 2 "B" 1 2 "BH" 99 1 "BI" 100 1 "C*" 255 1 "C+" 256 1 "K=" 999 0 "K>" 1000 1 "BQ!" 9999 0 "BQ#" 10000 0 "H'f" 65535 0 "H'g" 65536 0 "L-`" 99999 -1 "L-{" 100000 -1 "7G+" 500000 0 "BaNz" 999999 -1 "BaN0" 1000000 -3 "7`7nL" 4294967295 -3 "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:
40.5 ms | 402 KiB | 8 Q