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; } function duration($val) { if ($val < 24) { return sprintf('%d', $val).'h'; } if ($val < 24*10) { return sprintf('%1.1f', $val/24).'d'; } if ($val < 168*10) { return sprintf('%1.1f', $val/168).'w'; } //if ($val < 730*10) { // return sprintf('%1.1f', $val/730).'m'; //} return sprintf('%1.1f', $val/8760).'y'; } function cmp($val) { return strlen(gdr_encode($val))+2-strlen($val); } function insert(&$vals, $n) { $min = intval('1'.str_repeat('0', $n-1)); $max = intval(str_repeat('9', $n)); $vals[] = $min; $vals[] = $max; $cmp = cmp($min); $cmp_max = cmp($max); if ($cmp !== $cmp_max) { return; } while ($min < $max) { $mid = round(($min+$max)/2, 0)-1; $k = cmp($mid); echo "$min=>$cmp $mid=>$k $max=>$cmp_max\n"; if ($k == $cmp && $k !== cmp($mid+1)) { $vals[] = $mid; $vals[] = $mid+1; return; } if ($k > $cmp) { $max = $mid-1; } else { $min = $mid+1; } } } $vals = array(0); for ($i=1; $i<8; $i++) { insert($vals, $i); } $vals = array_unique($vals); sort($vals); //$vals = array( // 0, 1, 99, 100, 255, 256, 999, 1000, 9999, 10000, 65535, 65536, 99999, // 100000, 250000, 500000, 750000, 999999, 1000000, 9999999, //4294967295, 4294967296 //); echo sprintf("%7s %7s %7s %4s\n", 'num', 'str', 'time', 'cmp'); foreach ($vals as $val) { $enc = gdr_encode($val); $dec = gdr_decode($enc); if ($dec !== $val) { echo "ERROR: $val => $enc => $dec\n"; } else { echo sprintf("%7d %7s %7s %4d\n", $dec, "\"$enc\"", duration($val), strlen($enc)+2-strlen($val)); } }
Output for git.master, git.master_jit, rfc.property-hooks
1=>2 4=>2 9=>2 5=>2 6=>2 9=>2 7=>2 7=>2 9=>2 8=>2 8=>2 9=>2 100=>1 549=>1 999=>1 550=>1 774=>1 999=>1 775=>1 886=>1 999=>1 887=>1 942=>1 999=>1 943=>1 970=>1 999=>1 971=>1 984=>1 999=>1 985=>1 991=>1 999=>1 992=>1 995=>1 999=>1 996=>1 997=>1 999=>1 998=>1 998=>1 999=>1 10000=>0 54999=>0 99999=>0 55000=>0 77499=>0 99999=>0 77500=>0 88749=>0 99999=>0 88750=>0 94374=>0 99999=>0 94375=>0 97186=>0 99999=>0 97187=>0 98592=>0 99999=>0 98593=>0 99295=>0 99999=>0 99296=>0 99647=>0 99999=>0 99648=>0 99823=>0 99999=>0 99824=>0 99911=>0 99999=>0 99912=>0 99955=>0 99999=>0 99956=>0 99977=>0 99999=>0 99978=>0 99988=>0 99999=>0 99989=>0 99993=>0 99999=>0 99994=>0 99996=>0 99999=>0 99997=>0 99997=>0 99999=>0 99998=>0 99998=>0 99999=>0 1000000=>-1 5499999=>-1 9999999=>-1 5500000=>-1 7749999=>-1 9999999=>-1 7750000=>-1 8874999=>-1 9999999=>-1 8875000=>-1 9437499=>-1 9999999=>-1 9437500=>-1 9718749=>-1 9999999=>-1 9718750=>-1 9859374=>-1 9999999=>-1 9859375=>-1 9929686=>-1 9999999=>-1 9929687=>-1 9964842=>-1 9999999=>-1 9964843=>-1 9982420=>-1 9999999=>-1 9982421=>-1 9991209=>-1 9999999=>-1 9991210=>-1 9995604=>-1 9999999=>-1 9995605=>-1 9997801=>-1 9999999=>-1 9997802=>-1 9998900=>-1 9999999=>-1 9998901=>-1 9999449=>-1 9999999=>-1 9999450=>-1 9999724=>-1 9999999=>-1 9999725=>-1 9999861=>-1 9999999=>-1 9999862=>-1 9999930=>-1 9999999=>-1 9999931=>-1 9999964=>-1 9999999=>-1 9999965=>-1 9999981=>-1 9999999=>-1 9999982=>-1 9999990=>-1 9999999=>-1 9999991=>-1 9999994=>-1 9999999=>-1 9999995=>-1 9999996=>-1 9999999=>-1 9999997=>-1 9999997=>-1 9999999=>-1 9999998=>-1 9999998=>-1 9999999=>-1 num str time cmp 0 "" 0h 1 1 "B" 1h 2 9 "J" 9h 2 10 "K" 10h 1 99 "BH" 4.1d 2 100 "BI" 4.2d 1 999 "K=" 5.9w 1 1000 "K>" 6.0w 0 9999 "BQ!" 1.1y 1 10000 "BQ#" 1.1y 0 99999 "L-`" 11.4y 0 100000 "L-{" 11.4y -1 999999 "BaNz" 114.2y 0 1000000 "BaN0" 114.2y -1 9999999 "M;r7" 1141.6y -1

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:
38.11 ms | 409 KiB | 8 Q