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*1024) . "\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 RPt2C
Output for 4.3.0 - 7.1.0
AAQ AAg AAw ABA ABQ ABg ABw ACA ACQ ACg ACw ADA ADQ ADg ADw AEA AEQ AEg AEw AFA AFQ AFg AFw AGA AGQ AGg AGw AHA AHQ AHg AHw AIA AIQ AIg AIw AJA AJQ AJg AJw AKA AKQ AKg AKw ALA ALQ ALg ALw AMA AMQ AMg AMw ANA ANQ ANg ANw AOA AOQ AOg AOw APA APQ APg APw AAAB AAQB AAgB AAwB ABAB ABQB ABgB ABwB ACAB ACQB ACgB ACwB ADAB ADQB ADgB ADwB AEAB AEQB AEgB AEwB AFAB AFQB AFgB AFwB AGAB AGQB AGgB AGwB AHAB AHQB AHgB AHwB AIAB AIQB AIgB AIwB AJAB AJQB AJgB AJwB AKAB AKQB AKgB AKwB ALAB ALQB ALgB ALwB AMAB AMQB AMgB AMwB ANAB ANQB ANgB ANwB AOAB AOQB AOgB AOwB APAB APQB APgB APwB AAAC AAQC AAgC AAwC ABAC ABQC ABgC ABwC ACAC ACQC ACgC ACwC ADAC ADQC ADgC ADwC AEAC AEQC AEgC AEwC AFAC AFQC AFgC AFwC AGAC AGQC AGgC AGwC AHAC AHQC AHgC AHwC AIAC AIQC AIgC AIwC AJAC AJQC AJgC AJwC AKAC AKQC AKgC AKwC ALAC ALQC ALgC ALwC AMAC AMQC AMgC AMwC ANAC ANQC ANgC ANwC AOAC AOQC AOgC AOwC APAC APQC APgC APwC AAAD AAQD AAgD AAwD ABAD ABQD ABgD ABwD ACAD ACQD ACgD ACwD ADAD ADQD ADgD ADwD AEAD AEQD AEgD AEwD AFAD AFQD AFgD AFwD AGAD AGQD AGgD AGwD AHAD AHQD AHgD AHwD AIAD AIQD AIgD AIwD AJAD AJQD AJgD AJwD AKAD AKQD AKgD AKwD ALAD ALQD ALgD ALwD AMAD AMQD AMgD AMwD ANAD ANQD ANgD ANwD AOAD AOQD AOgD AOwD APAD APQD APgD APwD