3v4l.org

run code in 300+ PHP versions simultaneously
<?php class LZW { function compress($uncompressed) { $dictSize = 256; $dictionary = array(); for ($i = 0; $i < 256; $i++) { $dictionary[chr($i)] = $i; } $w = ""; $result = ""; for ($i = 0; $i < strlen($uncompressed); $i++) { $c = $this->charAt($uncompressed, $i); $wc = $w.$c; if (isset($dictionary[$wc])) { $w = $wc; } else { if ($result != "") { $result .= ",".$dictionary[$w]; } else { $result .= $dictionary[$w]; } $dictionary[$wc] = $dictSize++; $w = "".$c; } } if ($w != "") { if ($result != "") { $result .= ",".$dictionary[$w]; } else { $result .= $dictionary[$w]; } } return $result; } function decompress($compressed) { $compressed = explode(",", $compressed); $dictSize = 256; $dictionary = array(); for ($i = 1; $i < 256; $i++) { $dictionary[$i] = chr($i); } $w = chr($compressed[0]); $result = $w; for ($i = 1; $i < count($compressed); $i++) { $entry = ""; $k = $compressed[$i]; if (isset($dictionary[$k])) { $entry = $dictionary[$k]; } else if ($k == $dictSize) { $entry = $w.$this->charAt($w, 0); } else { return null; } $result .= $entry; $dictionary[$dictSize++] = $w.$this->charAt($entry, 0); $w = $entry; } return $result; } function charAt($string, $index){ if($index < mb_strlen($string)){ return mb_substr($string, $index, 1); } else{ return -1; } } } $lzw = new LZW(); echo $lzw->decompress("dGl0bGUgw4ljaGFuZ2VzIExNNwoKZVNtaWxlLT4rTE03OiBBcnRpY2xlCkxNNy0-LQAWBjogUmV0b3VyABQJACUPUkVDACEPTURTAEkQT1AAPhZPUAoAaAUtPgBlCEltYWdlIHN0b2Nr");
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught TypeError: chr(): Argument #1 ($codepoint) must be of type int, string given in /in/0iiFb:42 Stack trace: #0 /in/0iiFb(42): chr('dGl0bGUgw4ljaGF...') #1 /in/0iiFb(70): LZW->decompress(Array) #2 {main} thrown in /in/0iiFb on line 42
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:
99.27 ms | 401 KiB | 8 Q