3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyFilter extends php_user_filter { private $data = ''; public function filter($in, $out, &$consumed, $closing) { $return = PSFS_FEED_ME; // While input data is available, continue to read it. while ($bucket_in = stream_bucket_make_writeable($in)) { $this->data .= $bucket_in->data; $consumed += $bucket_in->datalen; // Process whole lines. while (preg_match('/(.*?)[\r\n]+(.*)/s', $this->data, $match) === 1) { list(, $data, $this->data) = $match; // Send this record output. $data = strrev($data) . PHP_EOL; $bucket_out = stream_bucket_new($this->stream, $data); $return = PSFS_PASS_ON; stream_bucket_append($out, $bucket_out); } } // Process the final line. if ($closing && $this->data !== '') { $data = strrev($this->data) . PHP_EOL; $bucket_out = stream_bucket_new($this->stream, $data); $return = PSFS_PASS_ON; stream_bucket_append($out, $bucket_out); } return $return; } } stream_filter_register('my-filter', 'MyFilter'); $input = "Line one\nLine two\nLine three"; $stream = fopen('data://text/plain,' . $input, 'r'); stream_filter_append($stream, 'my-filter'); $output = ''; while (!feof($stream)) { $output .= fread($stream, 16); } fclose($stream); echo $output;
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of MyFilter::filter($in, $out, &$consumed, $closing) should either be compatible with php_user_filter::filter($in, $out, &$consumed, bool $closing): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/kaeRJ on line 5 eno eniL owt eniL eerht eniL

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