3v4l.org

run code in 300+ PHP versions simultaneously
<?php $txt = <<<TXT Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 TXT; class FileObject extends SplFileObject { #[\ReturnTypeWillChange] public function seek($offset) { if ($offset < 0) { throw new Exception("Can't seek file: " . $this->getPathname() . " to negative offset: $offset"); } if ($offset === 0) { parent::seek(0); return; } $this->rewind(); for ($i = 0; $i < $offset; $i++) { $this->fgets(); $this->next(); if ($this->eof()) { break; } } //$this->current(); } } $file = new FileObject('php://memory', 'w+'); $file->fwrite($txt); echo 'Seeking line 2...', PHP_EOL; $file->seek(1); echo 'Position in the file: ', $file->ftell(), PHP_EOL; echo 'Rest of the file: ', PHP_EOL, $file->fread(5000); echo PHP_EOL, '-------------', PHP_EOL; echo 'Seeking line last line...', PHP_EOL; $file->seek(PHP_INT_MAX); $lastLine = $file->key(); $offset = max($lastLine - 1, 0); $file->seek($offset); echo 'Position in the file: ', $file->ftell(), PHP_EOL; echo 'Rest of the file: ', PHP_EOL, $file->fread(5000);
Output for git.master, git.master_jit, rfc.literals
Seeking line 2... Position in the file: 7 Rest of the file: Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 ------------- Seeking line last line... Position in the file: 49 Rest of the file: Line 8

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:
27.61 ms | 531 KiB | 13 Q