3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function pack_encode($val) { $str = ''; while ($val > 0) { $str .= chr($val & 0xFF); $val = $val >> 8; } // "/" json-encodes poorly and "=" is padding return str_replace( array('/', '='), array('_', ''), base64_encode($str) ); } for ($i=0; $i<256; $i++) { echo pack_encode($i*256) . "\n"; } /* $arr = array(); $packed = pack('N', 32767); for ($i=0; $i<strlen($packed); $i++) { $arr[$i] = ord($packed[$i]); } print_r($arr); function pack_encode($val) { $b64 = base64_encode(pack($format, $val)); return str_replace(array('/', '='), array('_', ''), $b64); // "/" json-encodes poorly and "=" is padding } function pack_decode($bin) { $b64 = str_replace('_', '/', $bin); // un-padded $data = unpack('C'.(length($bin)/2), base64_decode($b64, false)); $val = 0; foreach ($data as $v) { $val = ($val<<$width) | $v; } return $val; } $max = 32767; $n = 20; $step = intval($max/$n); for ($i=0; $i<=$n; $i++) { $val = $i*$step; $enc = pack_encode($val); $dec = pack_decode($val); echo "$enc $dec $val\n"; } */
based on OktGn
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
AAE AAI AAM AAQ AAU AAY AAc AAg AAk AAo AAs AAw AA0 AA4 AA8 ABA ABE ABI ABM ABQ ABU ABY ABc ABg ABk ABo ABs ABw AB0 AB4 AB8 ACA ACE ACI ACM ACQ ACU ACY ACc ACg ACk ACo ACs ACw AC0 AC4 AC8 ADA ADE ADI ADM ADQ ADU ADY ADc ADg ADk ADo ADs ADw AD0 AD4 AD8 AEA AEE AEI AEM AEQ AEU AEY AEc AEg AEk AEo AEs AEw AE0 AE4 AE8 AFA AFE AFI AFM AFQ AFU AFY AFc AFg AFk AFo AFs AFw AF0 AF4 AF8 AGA AGE AGI AGM AGQ AGU AGY AGc AGg AGk AGo AGs AGw AG0 AG4 AG8 AHA AHE AHI AHM AHQ AHU AHY AHc AHg AHk AHo AHs AHw AH0 AH4 AH8 AIA AIE AII AIM AIQ AIU AIY AIc AIg AIk AIo AIs AIw AI0 AI4 AI8 AJA AJE AJI AJM AJQ AJU AJY AJc AJg AJk AJo AJs AJw AJ0 AJ4 AJ8 AKA AKE AKI AKM AKQ AKU AKY AKc AKg AKk AKo AKs AKw AK0 AK4 AK8 ALA ALE ALI ALM ALQ ALU ALY ALc ALg ALk ALo ALs ALw AL0 AL4 AL8 AMA AME AMI AMM AMQ AMU AMY AMc AMg AMk AMo AMs AMw AM0 AM4 AM8 ANA ANE ANI ANM ANQ ANU ANY ANc ANg ANk ANo ANs ANw AN0 AN4 AN8 AOA AOE AOI AOM AOQ AOU AOY AOc AOg AOk AOo AOs AOw AO0 AO4 AO8 APA APE API APM APQ APU APY APc APg APk APo APs APw AP0 AP4 AP8