3v4l.org

run code in 300+ PHP versions simultaneously
<?php function pack_encode($val) { $str = array(); 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"; } */
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught TypeError: base64_encode(): Argument #1 ($string) must be of type string, array given in /in/OktGn:13 Stack trace: #0 /in/OktGn(13): base64_encode(Array) #1 /in/OktGn(18): pack_encode(0) #2 {main} thrown in /in/OktGn on line 13
Process exited with code 255.

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:
47.01 ms | 401 KiB | 8 Q